From f36e3b26d4388416b918e39a96646a73196254e3 Mon Sep 17 00:00:00 2001 From: ashar Date: Wed, 5 Jun 2024 09:29:43 +0700 Subject: [PATCH] feat(SPG-125) wip Logging --- src/app.module.ts | 12 +- .../modules/domain/usecase/base.manager.ts | 15 +-- .../usecase/managers/base-create.manager.ts | 21 ++++ .../domain/exceptions/handled-exception.ts | 20 ++++ src/core/strings/constants/table.constants.ts | 2 + .../auth/domain/auth.orchestrator.ts | 5 +- .../configuration/couch/couch.module.ts | 23 ++-- .../couch/infrastructure/couch.controller.ts | 104 +++++++++--------- src/modules/configuration/log/constants.ts | 0 .../log/data/models/error-log.model.ts | 29 +++++ .../log/data/models/log.model.ts | 38 +++++++ .../log/data/services/error-log.service.ts | 17 +++ .../log/data/services/log.service.ts | 17 +++ .../log/domain/entities/error-log.entity.ts | 12 ++ .../log/domain/entities/error-log.event.ts | 5 + .../log/domain/entities/log.entity.ts | 15 +++ .../log/domain/entities/log.event.ts | 5 + .../log/domain/handlers/error-log.handler.ts | 11 ++ .../log/domain/handlers/log.handler.ts | 11 ++ src/modules/configuration/log/index.ts | 0 src/modules/configuration/log/log.module.ts | 28 +++++ ...ivilege-configuration-data.orchestrator.ts | 2 +- .../user-privilege-data.orchestrator.ts | 21 ++-- 23 files changed, 323 insertions(+), 90 deletions(-) create mode 100644 src/modules/configuration/log/constants.ts create mode 100644 src/modules/configuration/log/data/models/error-log.model.ts create mode 100644 src/modules/configuration/log/data/models/log.model.ts create mode 100644 src/modules/configuration/log/data/services/error-log.service.ts create mode 100644 src/modules/configuration/log/data/services/log.service.ts create mode 100644 src/modules/configuration/log/domain/entities/error-log.entity.ts create mode 100644 src/modules/configuration/log/domain/entities/error-log.event.ts create mode 100644 src/modules/configuration/log/domain/entities/log.entity.ts create mode 100644 src/modules/configuration/log/domain/entities/log.event.ts create mode 100644 src/modules/configuration/log/domain/handlers/error-log.handler.ts create mode 100644 src/modules/configuration/log/domain/handlers/log.handler.ts create mode 100644 src/modules/configuration/log/index.ts create mode 100644 src/modules/configuration/log/log.module.ts diff --git a/src/app.module.ts b/src/app.module.ts index 43e40f5..e393a90 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,6 +1,5 @@ import { Module, Scope } from '@nestjs/common'; import { RefreshTokenInterceptor, SessionModule } from './core/sessions'; -import { JWTGuard } from './core/guards'; import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core'; import { HttpExceptionFilter, TransformInterceptor } from './core/response'; import { ApmModule } from './core/apm'; @@ -16,6 +15,9 @@ import { PrivilegeService } from './core/guards/domain/services/privilege.servic import { UserModel } from './modules/user-related/user/data/models/user.model'; import { AuthModule } from './modules/configuration/auth/auth.module'; import { UserModule } from './modules/user-related/user/user.module'; +import { LogModel } from './modules/configuration/log/data/models/log.model'; +import { ErrorLogModel } from './modules/configuration/log/data/models/error-log.model'; +import { LogModule } from './modules/configuration/log/log.module'; @Module({ imports: [ @@ -31,13 +33,19 @@ import { UserModule } from './modules/user-related/user/user.module'; username: process.env.DEFAULT_DB_USER, password: process.env.DEFAULT_DB_PASS, database: process.env.DEFAULT_DB_NAME, - entities: [...UserPrivilegeModels, UserModel], + entities: [ + ...UserPrivilegeModels, + UserModel, + LogModel, + ErrorLogModel, + ], synchronize: false, }), CqrsModule, SessionModule, AuthModule, CouchModule, + LogModule, UserModule, UserPrivilegeModule, diff --git a/src/core/modules/domain/usecase/base.manager.ts b/src/core/modules/domain/usecase/base.manager.ts index b06fb96..96b38f3 100644 --- a/src/core/modules/domain/usecase/base.manager.ts +++ b/src/core/modules/domain/usecase/base.manager.ts @@ -3,14 +3,16 @@ import { EventBus } from '@nestjs/cqrs'; import { UserProvider, UsersSession } from 'src/core/sessions'; import { BLANK_USER } from 'src/core/strings/constants/base.constants'; import { EventTopics } from 'src/core/strings/constants/interface.constants'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; import { QueryRunner } from 'typeorm'; @Injectable() export abstract class BaseManager { public user: UsersSession; - public queryRunner: QueryRunner; public dataService: any; protected data: any; + public queryRunner: QueryRunner; + protected tableName: TABLE_NAME; @Inject() protected userProvider: UserProvider; @Inject() @@ -26,11 +28,12 @@ export abstract class BaseManager { } } - setService(dataService) { + setService(dataService, tableName) { this.dataService = dataService; + this.tableName = tableName; this.queryRunner = this.dataService .getRepository() - .manager.connection.createQueryRunner(); + .manager.connection.createQueryRunner(tableName); } abstract get eventTopics(): EventTopics[]; @@ -62,8 +65,6 @@ export abstract class BaseManager { this.baseLog.verbose('commitTransaction'); await this.queryRunner.commitTransaction(); - this.publishEvents(); - await this.queryRunner.release(); } catch (e) { if (e.response) throw new Error(JSON.stringify(e.response)); @@ -80,8 +81,4 @@ export abstract class BaseManager { abstract process(): Promise; abstract afterProcess(): Promise; - - async publishEvents() { - if (!this.eventTopics.length) return; - } } diff --git a/src/core/modules/domain/usecase/managers/base-create.manager.ts b/src/core/modules/domain/usecase/managers/base-create.manager.ts index d3a7991..aee4ad4 100644 --- a/src/core/modules/domain/usecase/managers/base-create.manager.ts +++ b/src/core/modules/domain/usecase/managers/base-create.manager.ts @@ -1,5 +1,7 @@ import { CheckDuplicateHelper } from 'src/core/helpers/query/check-duplicate.helpers'; import { BaseManager } from '../base.manager'; +import { RecordLog } from 'src/modules/configuration/log/domain/entities/log.event'; +import { OPERATION } from 'src/core/strings/constants/base.constants'; export abstract class BaseCreateManager extends BaseManager { protected result: Entity; @@ -37,6 +39,8 @@ export abstract class BaseCreateManager extends BaseManager { this.entityTarget, this.data, ); + + this.publishEvents(); } async getResult(): Promise { @@ -46,4 +50,21 @@ export abstract class BaseCreateManager extends BaseManager { }, }); } + + async publishEvents() { + + this.eventBus.publish( + new RecordLog({ + id: this.result['id'], + old: null, + data: this.result, + user: this.user, + description: '', + module: this.tableName, + op: OPERATION.CREATE, + }) + ) + + // if (!this.eventTopics.length) return; + } } diff --git a/src/core/response/domain/exceptions/handled-exception.ts b/src/core/response/domain/exceptions/handled-exception.ts index 2b76ef2..47d1433 100644 --- a/src/core/response/domain/exceptions/handled-exception.ts +++ b/src/core/response/domain/exceptions/handled-exception.ts @@ -5,10 +5,18 @@ import { HttpException, HttpStatus, } from '@nestjs/common'; +import { EventBus } from '@nestjs/cqrs'; import { Response } from 'express'; +import { OPERATION } from 'src/core/strings/constants/base.constants'; +import { RecordErrorLog } from 'src/modules/configuration/log/domain/entities/error-log.event'; @Catch() export class HttpExceptionFilter implements ExceptionFilter { + + constructor( + private eventBus: EventBus, + ) {} + catch(exception: any, host: ArgumentsHost) { const ctx = host.switchToHttp(); const response = ctx.getResponse(); @@ -41,6 +49,18 @@ export class HttpExceptionFilter implements ExceptionFilter { }; } + this.eventBus.publish( + new RecordErrorLog({ + id: '', + old: null, + data: null, + user: null, + description: '', + module: null, + op: OPERATION.CREATE, + }) + ) + response.status(status).json(body); } } diff --git a/src/core/strings/constants/table.constants.ts b/src/core/strings/constants/table.constants.ts index 669b7e3..560e1ca 100644 --- a/src/core/strings/constants/table.constants.ts +++ b/src/core/strings/constants/table.constants.ts @@ -1,4 +1,6 @@ export enum TABLE_NAME { + LOG = 'logs', + ERROR_LOG = 'log_errors', USER = 'users', USER_PRIVILEGE = 'user_privileges', USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations', diff --git a/src/modules/configuration/auth/domain/auth.orchestrator.ts b/src/modules/configuration/auth/domain/auth.orchestrator.ts index e46c00d..0f068e4 100644 --- a/src/modules/configuration/auth/domain/auth.orchestrator.ts +++ b/src/modules/configuration/auth/domain/auth.orchestrator.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { UserDataService } from 'src/modules/user-related/user/data/services.ts/user-data.service'; import { LoginManager } from './managers/login.manager'; import { LogoutManager } from './managers/logout.manager'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; @Injectable() export class AuthOrchestrator { @@ -13,13 +14,13 @@ export class AuthOrchestrator { async login(data): Promise { this.loginManager.setData(data); - this.loginManager.setService(this.serviceData); + this.loginManager.setService(this.serviceData, TABLE_NAME.USER); await this.loginManager.execute(); return this.loginManager.getResult(); } async logout(): Promise { - this.logoutManager.setService(this.serviceData); + this.logoutManager.setService(this.serviceData, TABLE_NAME.USER); await this.logoutManager.execute(); return this.logoutManager.getResult(); } diff --git a/src/modules/configuration/couch/couch.module.ts b/src/modules/configuration/couch/couch.module.ts index f178f74..69bb385 100644 --- a/src/modules/configuration/couch/couch.module.ts +++ b/src/modules/configuration/couch/couch.module.ts @@ -1,17 +1,14 @@ -import { ConfigModule } from "@nestjs/config"; -import { CouchDataController } from "./infrastructure/couch.controller"; -import { Module } from "@nestjs/common"; +import { ConfigModule } from '@nestjs/config'; +import { CouchDataController } from './infrastructure/couch.controller'; +import { Module } from '@nestjs/common'; @Module({ - imports: [ - ConfigModule.forRoot(), + imports: [ + ConfigModule.forRoot(), // TypeOrmModule.forFeature([UserPrivilegeModel], CONNECTION_NAME.DEFAULT), // CqrsModule, - ], - controllers: [ - CouchDataController - ], - providers: [ - ], - }) - export class CouchModule {} \ No newline at end of file + ], + controllers: [CouchDataController], + providers: [], +}) +export class CouchModule {} diff --git a/src/modules/configuration/couch/infrastructure/couch.controller.ts b/src/modules/configuration/couch/infrastructure/couch.controller.ts index d5028b7..dfa5b2a 100644 --- a/src/modules/configuration/couch/infrastructure/couch.controller.ts +++ b/src/modules/configuration/couch/infrastructure/couch.controller.ts @@ -1,66 +1,64 @@ -import { Body, Controller, Get, Post } from "@nestjs/common"; +import { Body, Controller, Get, Post } from '@nestjs/common'; -import { ApiTags } from "@nestjs/swagger"; -import { Unprotected } from "src/core/guards"; -import * as Nano from 'nano' -import { CreateUserPrivilegeDto } from "src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto"; +import { ApiTags } from '@nestjs/swagger'; +import { Unprotected } from 'src/core/guards'; +import * as Nano from 'nano'; +import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto'; @ApiTags(`couch`) @Controller('couch') @Unprotected() export class CouchDataController { - - @Post() - async createDoc( - @Body() entity: CreateUserPrivilegeDto - ) { - try { - let n = Nano('http://admin:secret@127.0.0.1:5984') - let db = await n.db.create(entity.name) - } catch (error) { - console.log(error, 'dsa') - } + @Post() + async createDoc(@Body() entity: CreateUserPrivilegeDto) { + try { + let n = Nano('http://admin:secret@127.0.0.1:5984'); + let db = await n.db.create(entity.name); + } catch (error) { + console.log(error, 'dsa'); } + } - @Post('doc') - async createDocs( - @Body() entity: CreateUserPrivilegeDto - ) { - try { - const nano = require("nano")("http://admin:secret@127.0.0.1:5984"); - const people = nano.db.use('string'); - console.log(await people.info()) - const data = { - id: '1212', - name: 'dsadas' - } - // await people.insert(data) + @Post('doc') + async createDocs(@Body() entity: CreateUserPrivilegeDto) { + try { + const nano = require('nano')('http://admin:secret@127.0.0.1:5984'); + const people = nano.db.use('string'); + console.log(await people.info()); + const data = { + id: '1212', + name: 'dsadas', + }; + // await people.insert(data) - people.changesReader.start() - .on('change', (change) => { console.log(change) }) - .on('batch', (b) => { - console.log('a batch of', b.length, 'changes has arrived'); - }).on('seq', (s) => { - console.log('sequence token', s); - }).on('error', (e) => { - console.error('error', e); - }) - - } catch (error) { - console.log(error, 'dsa') - } + people.changesReader + .start() + .on('change', (change) => { + console.log(change); + }) + .on('batch', (b) => { + console.log('a batch of', b.length, 'changes has arrived'); + }) + .on('seq', (s) => { + console.log('sequence token', s); + }) + .on('error', (e) => { + console.error('error', e); + }); + } catch (error) { + console.log(error, 'dsa'); } + } - @Get() - async getDoc( - ) { - try { - let n = Nano('http://admin:secret@127.0.0.1:5984') - const people = n.use('string'); + @Get() + async getDoc() { + try { + let n = Nano('http://admin:secret@127.0.0.1:5984'); + const people = n.use('string'); - // return people.get(); - } catch (error) { - console.log(error, 'dsa') - } + // return people.get(); + } catch (error) { + console.log(error, 'dsa'); } -} \ No newline at end of file + } +} diff --git a/src/modules/configuration/log/constants.ts b/src/modules/configuration/log/constants.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/configuration/log/data/models/error-log.model.ts b/src/modules/configuration/log/data/models/error-log.model.ts new file mode 100644 index 0000000..0ae07d4 --- /dev/null +++ b/src/modules/configuration/log/data/models/error-log.model.ts @@ -0,0 +1,29 @@ +import { BaseCoreModel } from "src/core/modules/data/model/base-core.model"; +import { ErrorLogEntity } from "../../domain/entities/error-log.entity"; +import { Column } from "typeorm"; + +export class ErrorLogModel extends BaseCoreModel implements ErrorLogEntity { + @Column('varchar', { name: 'data_id', nullable: true }) + data_id: string; + + @Column('varchar', { name: 'module', nullable: true }) + module: string; + + @Column('varchar', { name: 'sub_module', nullable: true }) + sub_module: string; + + @Column('text', { name: 'description', nullable: true }) + description: string; + + @Column('json', { name: 'message', nullable: true }) + message: string; + + @Column('bigint', { name: 'created_at', nullable: true }) + created_at: number; + + @Column('varchar', { name: 'creator_name', nullable: true }) + creator_name: string; + + @Column('varchar', { name: 'creator_id', nullable: true }) + creator_id: string; +} \ No newline at end of file diff --git a/src/modules/configuration/log/data/models/log.model.ts b/src/modules/configuration/log/data/models/log.model.ts new file mode 100644 index 0000000..8c8a72e --- /dev/null +++ b/src/modules/configuration/log/data/models/log.model.ts @@ -0,0 +1,38 @@ +import { BaseCoreModel } from "src/core/modules/data/model/base-core.model"; +import { LogEntity } from "../../domain/entities/log.entity"; +import { Column, Entity } from "typeorm"; +import { OPERATION } from "src/core/strings/constants/base.constants"; +import { TABLE_NAME } from "src/core/strings/constants/table.constants"; + +@Entity(TABLE_NAME.LOG) +export class LogModel extends BaseCoreModel implements LogEntity { + @Column('varchar', { name: 'data_id', nullable: true }) + data_id: string; + + @Column('varchar', { name: 'module', nullable: true }) + module: string; + + @Column('varchar', { name: 'sub_module', nullable: true }) + sub_module: string; + + @Column('text', { name: 'description', nullable: true }) + description: string; + + @Column('varchar', { name: 'process', default: OPERATION.CREATE }) + process: OPERATION; + + @Column('json', { name: 'data', nullable: true }) + data: any; + + @Column('json', { name: 'old_data', nullable: true }) + old_data: any; + + @Column('bigint', { name: 'created_at', nullable: true }) + created_at: number; + + @Column('varchar', { name: 'creator_name', nullable: true }) + creator_name: string; + + @Column('varchar', { name: 'creator_id', nullable: true }) + creator_id: string; +} \ No newline at end of file diff --git a/src/modules/configuration/log/data/services/error-log.service.ts b/src/modules/configuration/log/data/services/error-log.service.ts new file mode 100644 index 0000000..eaa242e --- /dev/null +++ b/src/modules/configuration/log/data/services/error-log.service.ts @@ -0,0 +1,17 @@ +import { BaseDataService } from "src/core/modules/data/service/base-data.service"; +import { ErrorLogEntity } from "../../domain/entities/error-log.entity"; +import { Injectable } from "@nestjs/common"; +import { InjectRepository } from "@nestjs/typeorm"; +import { ErrorLogModel } from "../models/error-log.model"; +import { Repository } from "typeorm"; +import { CONNECTION_NAME } from "src/core/strings/constants/base.constants"; + +@Injectable() +export class ErrorLogService extends BaseDataService { + constructor( + @InjectRepository(ErrorLogModel, CONNECTION_NAME.DEFAULT) + private repo: Repository, + ) { + super(repo); + } +} \ No newline at end of file diff --git a/src/modules/configuration/log/data/services/log.service.ts b/src/modules/configuration/log/data/services/log.service.ts new file mode 100644 index 0000000..21ffa6c --- /dev/null +++ b/src/modules/configuration/log/data/services/log.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from "@nestjs/common"; +import { BaseDataService } from "src/core/modules/data/service/base-data.service"; +import { LogEntity } from "../../domain/entities/log.entity"; +import { LogModel } from "../models/log.model"; +import { InjectRepository } from "@nestjs/typeorm"; +import { CONNECTION_NAME } from "src/core/strings/constants/base.constants"; +import { Repository } from "typeorm"; + +@Injectable() +export class LogService extends BaseDataService { + constructor( + @InjectRepository(LogModel, CONNECTION_NAME.DEFAULT) + private repo: Repository, + ) { + super(repo); + } +} \ No newline at end of file diff --git a/src/modules/configuration/log/domain/entities/error-log.entity.ts b/src/modules/configuration/log/domain/entities/error-log.entity.ts new file mode 100644 index 0000000..a6eb640 --- /dev/null +++ b/src/modules/configuration/log/domain/entities/error-log.entity.ts @@ -0,0 +1,12 @@ +import { BaseCoreEntity } from "src/core/modules/domain/entities/base-core.entity"; + +export interface ErrorLogEntity extends BaseCoreEntity { + data_id: string; + message: string; + description: string; + module: string; + sub_module: string; + created_at: number; + creator_name: string; + creator_id: string; +} \ No newline at end of file diff --git a/src/modules/configuration/log/domain/entities/error-log.event.ts b/src/modules/configuration/log/domain/entities/error-log.event.ts new file mode 100644 index 0000000..ffbc10d --- /dev/null +++ b/src/modules/configuration/log/domain/entities/error-log.event.ts @@ -0,0 +1,5 @@ +import { IEvent } from "src/core/strings/constants/interface.constants"; + +export class RecordErrorLog { + constructor(public readonly data: IEvent) {} +} \ No newline at end of file diff --git a/src/modules/configuration/log/domain/entities/log.entity.ts b/src/modules/configuration/log/domain/entities/log.entity.ts new file mode 100644 index 0000000..5267a08 --- /dev/null +++ b/src/modules/configuration/log/domain/entities/log.entity.ts @@ -0,0 +1,15 @@ +import { BaseCoreEntity } from "src/core/modules/domain/entities/base-core.entity"; +import { OPERATION } from "src/core/strings/constants/base.constants"; + +export interface LogEntity extends BaseCoreEntity { + data_id: string; + process: OPERATION; + data: any; + old_data: any; + description: string; + module: string; + sub_module: string; + created_at: number; + creator_name: string; + creator_id: string; +} \ No newline at end of file diff --git a/src/modules/configuration/log/domain/entities/log.event.ts b/src/modules/configuration/log/domain/entities/log.event.ts new file mode 100644 index 0000000..0980c37 --- /dev/null +++ b/src/modules/configuration/log/domain/entities/log.event.ts @@ -0,0 +1,5 @@ +import { IEvent } from "src/core/strings/constants/interface.constants"; + +export class RecordLog { + constructor(public readonly data: IEvent) {} +} \ No newline at end of file diff --git a/src/modules/configuration/log/domain/handlers/error-log.handler.ts b/src/modules/configuration/log/domain/handlers/error-log.handler.ts new file mode 100644 index 0000000..a39451a --- /dev/null +++ b/src/modules/configuration/log/domain/handlers/error-log.handler.ts @@ -0,0 +1,11 @@ +import { EventsHandler, IEventHandler } from "@nestjs/cqrs"; +import { RecordErrorLog } from "../entities/error-log.event"; + +@EventsHandler(RecordErrorLog) +export class RecordErrorLogHandler implements IEventHandler { + + async handle(event: RecordErrorLog) { + console.log(event, 'das error') + } + +} \ No newline at end of file diff --git a/src/modules/configuration/log/domain/handlers/log.handler.ts b/src/modules/configuration/log/domain/handlers/log.handler.ts new file mode 100644 index 0000000..82fc347 --- /dev/null +++ b/src/modules/configuration/log/domain/handlers/log.handler.ts @@ -0,0 +1,11 @@ +import { EventsHandler, IEventHandler } from "@nestjs/cqrs"; +import { RecordLog } from "../entities/log.event"; + +@EventsHandler(RecordLog) +export class RecordLogHandler implements IEventHandler { + + async handle(event: RecordLog) { + console.log(event, 'log') + } + +} \ No newline at end of file diff --git a/src/modules/configuration/log/index.ts b/src/modules/configuration/log/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/configuration/log/log.module.ts b/src/modules/configuration/log/log.module.ts new file mode 100644 index 0000000..f4a94c2 --- /dev/null +++ b/src/modules/configuration/log/log.module.ts @@ -0,0 +1,28 @@ +import { Module } from "@nestjs/common"; +import { ConfigModule } from "@nestjs/config"; +import { CqrsModule } from "@nestjs/cqrs"; +import { TypeOrmModule } from "@nestjs/typeorm"; +import { LogModel } from "./data/models/log.model"; +import { ErrorLogModel } from "./data/models/error-log.model"; +import { CONNECTION_NAME } from "src/core/strings/constants/base.constants"; +import { RecordErrorLogHandler } from "./domain/handlers/error-log.handler"; +import { RecordLogHandler } from "./domain/handlers/log.handler"; +import { ErrorLogService } from "./data/services/error-log.service"; +import { LogService } from "./data/services/log.service"; + +@Module({ + imports: [ + ConfigModule.forRoot(), + TypeOrmModule.forFeature([LogModel, ErrorLogModel], CONNECTION_NAME.DEFAULT), + CqrsModule, + ], + controllers: [], + providers: [ + RecordLogHandler, + RecordErrorLogHandler, + + LogService, + ErrorLogService, + ], +}) +export class LogModule {} \ No newline at end of file diff --git a/src/modules/user-related/user-privilege/domain/usecases/user-privilege-configuration/user-privilege-configuration-data.orchestrator.ts b/src/modules/user-related/user-privilege/domain/usecases/user-privilege-configuration/user-privilege-configuration-data.orchestrator.ts index e0d6c09..445865b 100644 --- a/src/modules/user-related/user-privilege/domain/usecases/user-privilege-configuration/user-privilege-configuration-data.orchestrator.ts +++ b/src/modules/user-related/user-privilege/domain/usecases/user-privilege-configuration/user-privilege-configuration-data.orchestrator.ts @@ -16,7 +16,7 @@ export class UserPrivilegeConfigurationDataOrchestrator { async update(data): Promise { this.updateManager.setData(data); - this.updateManager.setService(this.serviceData); + this.updateManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE_CONFIGURATION); await this.updateManager.execute(); return this.updateManager.getResult(); } diff --git a/src/modules/user-related/user-privilege/domain/usecases/user-privilege/user-privilege-data.orchestrator.ts b/src/modules/user-related/user-privilege/domain/usecases/user-privilege/user-privilege-data.orchestrator.ts index 84b26d2..7312949 100644 --- a/src/modules/user-related/user-privilege/domain/usecases/user-privilege/user-privilege-data.orchestrator.ts +++ b/src/modules/user-related/user-privilege/domain/usecases/user-privilege/user-privilege-data.orchestrator.ts @@ -14,6 +14,7 @@ import { BatchConfirmUserPrivilegeManager } from './managers/batch-confirm-user- import { BatchInactiveUserPrivilegeManager } from './managers/batch-inactive-user-privilege.manager'; import { BatchActiveUserPrivilegeManager } from './managers/batch-active-user-privilege.manager'; import { BatchDeleteUserPrivilegeManager } from './managers/batch-delete-user-privilege.manager'; +import { TABLE_NAME } from 'src/core/strings/constants/table.constants'; @Injectable() export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrator { @@ -35,7 +36,7 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat async create(data): Promise { this.createManager.setData(data); - this.createManager.setService(this.serviceData); + this.createManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.createManager.execute(); await this.createManager.generateConfig(); return this.createManager.getResult(); @@ -43,63 +44,63 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat async update(dataId, data): Promise { this.updateManager.setData(dataId, data); - this.updateManager.setService(this.serviceData); + this.updateManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.updateManager.execute(); return this.updateManager.getResult(); } async delete(dataId): Promise { this.deleteManager.setData(dataId); - this.deleteManager.setService(this.serviceData); + this.deleteManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.deleteManager.execute(); return this.deleteManager.getResult(); } async batchDelete(dataIds: string[]): Promise { this.batchDeleteManager.setData(dataIds); - this.batchDeleteManager.setService(this.serviceData); + this.batchDeleteManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.batchDeleteManager.execute(); return this.batchDeleteManager.getResult(); } async active(dataId): Promise { this.activeManager.setData(dataId, STATUS.ACTIVE); - this.activeManager.setService(this.serviceData); + this.activeManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.activeManager.execute(); return this.activeManager.getResult(); } async batchActive(dataIds: string[]): Promise { this.batchActiveManager.setData(dataIds, STATUS.ACTIVE); - this.batchActiveManager.setService(this.serviceData); + this.batchActiveManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.batchActiveManager.execute(); return this.batchActiveManager.getResult(); } async confirm(dataId): Promise { this.confirmManager.setData(dataId, STATUS.ACTIVE); - this.confirmManager.setService(this.serviceData); + this.confirmManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.confirmManager.execute(); return this.confirmManager.getResult(); } async batchConfirm(dataIds: string[]): Promise { this.batchConfirmManager.setData(dataIds, STATUS.ACTIVE); - this.batchConfirmManager.setService(this.serviceData); + this.batchConfirmManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.batchConfirmManager.execute(); return this.batchConfirmManager.getResult(); } async inactive(dataId): Promise { this.inactiveManager.setData(dataId, STATUS.INACTIVE); - this.inactiveManager.setService(this.serviceData); + this.inactiveManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.inactiveManager.execute(); return this.inactiveManager.getResult(); } async batchInactive(dataIds: string[]): Promise { this.batchInactiveManager.setData(dataIds, STATUS.INACTIVE); - this.batchInactiveManager.setService(this.serviceData); + this.batchInactiveManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); await this.batchInactiveManager.execute(); return this.batchInactiveManager.getResult(); }