import { Injectable } from '@nestjs/common'; import { ACTIVITY_CATEGORIES, ActivityLogRepository, } from '../repository/activity-log.repository'; import { ActivityLog } from '../entity/activity-log.entity'; import { log } from 'console'; import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service'; import { UserData } from 'src/module/user/entity/user.entity'; function enrichData(category: string, logData: any): any { switch (category) { case ACTIVITY_CATEGORIES.STAGE: logData.color = '#06aed4'; logData.icon = 'stage'; break; case ACTIVITY_CATEGORIES.INTERACTION: logData.color = '#7a5af8'; logData.icon = 'interaction'; break; case ACTIVITY_CATEGORIES.FORM: logData.color = '#eaaa08'; logData.icon = 'form'; break; case ACTIVITY_CATEGORIES.ASSIGN: logData.color = '#16b364'; logData.icon = 'assign'; break; case ACTIVITY_CATEGORIES.MEETING: logData.color = '#7a5af8'; logData.icon = 'meeting'; break; case ACTIVITY_CATEGORIES.PROCESS: logData.color = '#06aed4'; logData.icon = 'process'; break; case ACTIVITY_CATEGORIES.STATUS: logData.color = '#06aed4'; logData.icon = 'status'; break; case ACTIVITY_CATEGORIES.TASK: logData.color = '#f63d68'; logData.icon = 'task'; break; case ACTIVITY_CATEGORIES.LEAD: logData.color = '#16b364'; logData.icon = 'lead'; break; case ACTIVITY_CATEGORIES.ASSESSMENT: logData.color = '#f63d68'; logData.icon = 'assessment'; break; case ACTIVITY_CATEGORIES.STAGEGROUP: logData.color = '#06aed4'; logData.icon = 'stage_group'; break; default: logData.color = '#ff0000'; logData.icon = 'DEFAULT'; } return logData; } @Injectable() export class ActivityLogService extends EntityServiceImpl { constructor(private readonly activityLogRepository: ActivityLogRepository) { super(); } async logActivity( logData: any, loggedInUser: UserData, ): Promise { const storeData = enrichData(logData.category.toUpperCase(), logData); storeData.entity_type = 'ACLG'; return super.createEntity(storeData, loggedInUser); } async getAllActivityLog( mapped_entity_type: string, mapped_entity_id: number | string, category: string, loggedInUser, ) { const result = this.activityLogRepository.getAllActivityLog( mapped_entity_type, mapped_entity_id, category, loggedInUser, ); return result; } async getAllActivityCategory( mapped_entity_id: number | string, mapped_entity_type: string, loggedInUser, ) { const result = this.activityLogRepository.getAllActivityCategory( mapped_entity_id, mapped_entity_type, loggedInUser, ); return result; } }