Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Alter Activity Log Entity Based On Employee #8771

Merged
merged 9 commits into from
Feb 17, 2025
14 changes: 7 additions & 7 deletions packages/contracts/src/lib/activity-log.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import {
ActorTypeEnum,
IBasePerEntityType,
IBasePerTenantAndOrganizationEntityModel,
ID,
JsonData
} from './base-entity.model';
import { IUser } from './user.model';
import { IEmployeeEntityInput } from './employee.model';

/**
* Interface representing an activity log entry.
*/
export interface IActivityLog extends IBasePerTenantAndOrganizationEntityModel, IBasePerEntityType {
export interface IActivityLog
extends IBasePerTenantAndOrganizationEntityModel,
IEmployeeEntityInput,
IBasePerEntityType {
action: ActionTypeEnum;
actorType?: ActorTypeEnum;
description?: string; // A short sentence describing the action performed. (E.g John Doe created this on 22.09.2024)
Expand All @@ -19,8 +21,6 @@ export interface IActivityLog extends IBasePerTenantAndOrganizationEntityModel,
updatedValues?: IActivityLogUpdatedValues[]; // Values after update (E.g For task : {title: ' First Task Updated', members: ['Member4Name', 'Member3Name'], projectId: 'project2UUId'})
previousEntities?: IActivityLogUpdatedValues[]; // Stores previous IDs or other values for related entities. Eg : {members: ['member_1_ID', 'member_2_ID']}
updatedEntities?: IActivityLogUpdatedValues[]; // Stores updated IDs, or other values for related entities. Eg : {members: ['member_1_ID', 'member_2_ID']},
creator?: IUser;
creatorId?: ID;
data?: JsonData;
}

Expand All @@ -38,6 +38,6 @@ export enum ActionTypeEnum {
}

/**
* Input type for activity log creation, excluding `creatorId` and `creator`.
* Input type for activity log creation, excluding `employeeId` and `employee`.
*/
export interface IActivityLogInput extends Omit<IActivityLog, 'creatorId' | 'creator'> {}
export interface IActivityLogInput extends Omit<IActivityLog, 'employeeId' | 'employee'> {}
14 changes: 7 additions & 7 deletions packages/core/src/lib/activity-log/activity-log.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { EntityRepositoryType } from '@mikro-orm/core';
import { JoinColumn, RelationId } from 'typeorm';
import { IsArray, IsEnum, IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
import { isMySQL, isPostgres } from '@gauzy/config';
import { BaseEntityEnum, ActionTypeEnum, ActorTypeEnum, IActivityLog, ID, IUser, JsonData } from '@gauzy/contracts';
import { TenantOrganizationBaseEntity, User } from '../core/entities/internal';
import { BaseEntityEnum, ActionTypeEnum, ActorTypeEnum, IActivityLog, ID, JsonData, IEmployee } from '@gauzy/contracts';
import { Employee, TenantOrganizationBaseEntity } from '../core/entities/internal';
import { ColumnIndex, MultiORMColumn, MultiORMEntity, MultiORMManyToOne } from '../core/decorators/entity';
import { ActorTypeTransformerPipe } from '../shared/pipes';
import { MikroOrmActivityLogRepository } from './repository/mikro-orm-activity-log.repository';
Expand Down Expand Up @@ -91,20 +91,20 @@ export class ActivityLog extends TenantOrganizationBaseEntity implements IActivi
*/

/**
* User performed action
* Employee performed action
*/
@MultiORMManyToOne(() => User, {
@MultiORMManyToOne(() => Employee, {
/** Indicates if relation column value can be nullable or not. */
nullable: true,

/** Database cascade action on delete. */
onDelete: 'CASCADE'
})
@JoinColumn()
creator?: IUser;
employee?: IEmployee;

@RelationId((it: ActivityLog) => it.creator)
@RelationId((it: ActivityLog) => it.employee)
@ColumnIndex()
@MultiORMColumn({ nullable: true, relationId: true })
creatorId?: ID;
employeeId?: ID;
}
4 changes: 2 additions & 2 deletions packages/core/src/lib/activity-log/activity-log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export class ActivityLogService extends TenantAwareCrudService<ActivityLog> {
async create(input: IActivityLogInput): Promise<IActivityLog> {
try {
// Retrieve the current user's ID from the request context
const creatorId = RequestContext.currentUserId();
const employeeId = RequestContext.currentEmployeeId();

// Retrieve the current tenant ID from the request context or use the provided tenantId
const tenantId = RequestContext.currentTenantId() || input.tenantId;

// Create the activity log entry using the provided input along with the tenantId and creatorId
return await super.create({ ...input, tenantId, creatorId });
return await super.create({ ...input, tenantId, employeeId });
} catch (error) {
console.log('Error while creating activity log:', error);
throw new BadRequestException('Error while creating activity log', error);
Expand Down
Loading
Loading