feat(format) formatting
continuous-integration/drone/tag Build is passing Details

pull/2/head devel_2.3
ashar 2024-06-05 14:37:03 +07:00
parent ca45d78e1d
commit 6165763a0b
19 changed files with 228 additions and 194 deletions

View File

@ -33,12 +33,7 @@ import { LogModule } from './modules/configuration/log/log.module';
username: process.env.DEFAULT_DB_USER, username: process.env.DEFAULT_DB_USER,
password: process.env.DEFAULT_DB_PASS, password: process.env.DEFAULT_DB_PASS,
database: process.env.DEFAULT_DB_NAME, database: process.env.DEFAULT_DB_NAME,
entities: [ entities: [...UserPrivilegeModels, UserModel, LogModel, ErrorLogModel],
...UserPrivilegeModels,
UserModel,
LogModel,
ErrorLogModel,
],
synchronize: false, synchronize: false,
}), }),
CqrsModule, CqrsModule,

View File

@ -39,7 +39,7 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
this.entityTarget, this.entityTarget,
this.data, this.data,
); );
this.publishEvents(); this.publishEvents();
} }
@ -50,9 +50,8 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
}, },
}); });
} }
async publishEvents() { async publishEvents() {
this.eventBus.publish( this.eventBus.publish(
new RecordLog({ new RecordLog({
id: this.result['id'], id: this.result['id'],
@ -62,8 +61,8 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
description: '', description: '',
module: this.tableName, module: this.tableName,
op: OPERATION.CREATE, op: OPERATION.CREATE,
}) }),
) );
// if (!this.eventTopics.length) return; // if (!this.eventTopics.length) return;
} }

View File

@ -7,15 +7,13 @@ import {
} from '@nestjs/common'; } from '@nestjs/common';
import { EventBus } from '@nestjs/cqrs'; import { EventBus } from '@nestjs/cqrs';
import { Response } from 'express'; import { Response } from 'express';
import { apm } from 'src/core/apm';
import { OPERATION } from 'src/core/strings/constants/base.constants'; import { OPERATION } from 'src/core/strings/constants/base.constants';
import { RecordErrorLog } from 'src/modules/configuration/log/domain/entities/error-log.event'; import { RecordErrorLog } from 'src/modules/configuration/log/domain/entities/error-log.event';
@Catch() @Catch()
export class HttpExceptionFilter implements ExceptionFilter { export class HttpExceptionFilter implements ExceptionFilter {
constructor(private eventBus: EventBus) {}
constructor(
private eventBus: EventBus,
) {}
catch(exception: any, host: ArgumentsHost) { catch(exception: any, host: ArgumentsHost) {
const ctx = host.switchToHttp(); const ctx = host.switchToHttp();
@ -49,17 +47,17 @@ export class HttpExceptionFilter implements ExceptionFilter {
}; };
} }
this.eventBus.publish( // this.eventBus.publish(
new RecordErrorLog({ // new RecordErrorLog({
id: '', // id: '',
old: null, // old: null,
data: null, // data: null,
user: null, // user: null,
description: '', // description: '',
module: null, // module: null,
op: OPERATION.CREATE, // op: OPERATION.CREATE,
}) // }),
) // );
response.status(status).json(body); response.status(status).json(body);
} }

View File

@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class Log1717560799195 implements MigrationInterface {
name = 'Log1717560799195';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "logs" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "data_id" character varying, "module" character varying, "sub_module" character varying, "description" text, "process" character varying NOT NULL DEFAULT 'Create', "data" json, "old_data" json, "created_at" bigint, "creator_name" character varying, "creator_id" character varying, CONSTRAINT "PK_fb1b805f2f7795de79fa69340ba" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "log_errors" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "data_id" character varying, "module" character varying, "sub_module" character varying, "description" text, "message" json, "created_at" bigint, "creator_name" character varying, "creator_id" character varying, CONSTRAINT "PK_d268ea9ac1074d41949daaae79d" PRIMARY KEY ("id"))`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "log_errors"`);
await queryRunner.query(`DROP TABLE "logs"`);
}
}

View File

@ -9,7 +9,7 @@ export const connectionSource = new DataSource({
username: process.env.DEFAULT_DB_USER, username: process.env.DEFAULT_DB_USER,
password: process.env.DEFAULT_DB_PASS, password: process.env.DEFAULT_DB_PASS,
database: process.env.DEFAULT_DB_NAME, database: process.env.DEFAULT_DB_NAME,
entities: ['src/modules/user-related/**/data/models/*.ts'], entities: ['src/modules/**/**/data/models/*.ts'],
migrationsTableName: 'migrations', migrationsTableName: 'migrations',
migrations: ['src/database/migrations/*.ts'], migrations: ['src/database/migrations/*.ts'],
synchronize: false, synchronize: false,

View File

@ -1,29 +1,34 @@
import { BaseCoreModel } from "src/core/modules/data/model/base-core.model"; import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
import { ErrorLogEntity } from "../../domain/entities/error-log.entity"; import { ErrorLogEntity } from '../../domain/entities/error-log.entity';
import { Column } from "typeorm"; import { Column, Entity } from 'typeorm';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
export class ErrorLogModel extends BaseCoreModel<ErrorLogEntity> implements ErrorLogEntity { @Entity(TABLE_NAME.ERROR_LOG)
@Column('varchar', { name: 'data_id', nullable: true }) export class ErrorLogModel
data_id: string; extends BaseCoreModel<ErrorLogEntity>
implements ErrorLogEntity
@Column('varchar', { name: 'module', nullable: true }) {
module: string; @Column('varchar', { name: 'data_id', nullable: true })
data_id: string;
@Column('varchar', { name: 'sub_module', nullable: true })
sub_module: string; @Column('varchar', { name: 'module', nullable: true })
module: string;
@Column('text', { name: 'description', nullable: true })
description: string; @Column('varchar', { name: 'sub_module', nullable: true })
sub_module: string;
@Column('json', { name: 'message', nullable: true })
message: string; @Column('text', { name: 'description', nullable: true })
description: string;
@Column('bigint', { name: 'created_at', nullable: true })
created_at: number; @Column('json', { name: 'message', nullable: true })
message: string;
@Column('varchar', { name: 'creator_name', nullable: true })
creator_name: string; @Column('bigint', { name: 'created_at', nullable: true })
created_at: number;
@Column('varchar', { name: 'creator_id', nullable: true })
creator_id: string; @Column('varchar', { name: 'creator_name', nullable: true })
} creator_name: string;
@Column('varchar', { name: 'creator_id', nullable: true })
creator_id: string;
}

View File

@ -1,38 +1,38 @@
import { BaseCoreModel } from "src/core/modules/data/model/base-core.model"; import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
import { LogEntity } from "../../domain/entities/log.entity"; import { LogEntity } from '../../domain/entities/log.entity';
import { Column, Entity } from "typeorm"; import { Column, Entity } from 'typeorm';
import { OPERATION } from "src/core/strings/constants/base.constants"; import { OPERATION } from 'src/core/strings/constants/base.constants';
import { TABLE_NAME } from "src/core/strings/constants/table.constants"; import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
@Entity(TABLE_NAME.LOG) @Entity(TABLE_NAME.LOG)
export class LogModel extends BaseCoreModel<LogEntity> implements LogEntity { export class LogModel extends BaseCoreModel<LogEntity> implements LogEntity {
@Column('varchar', { name: 'data_id', nullable: true }) @Column('varchar', { name: 'data_id', nullable: true })
data_id: string; data_id: string;
@Column('varchar', { name: 'module', nullable: true }) @Column('varchar', { name: 'module', nullable: true })
module: string; module: string;
@Column('varchar', { name: 'sub_module', nullable: true }) @Column('varchar', { name: 'sub_module', nullable: true })
sub_module: string; sub_module: string;
@Column('text', { name: 'description', nullable: true }) @Column('text', { name: 'description', nullable: true })
description: string; description: string;
@Column('varchar', { name: 'process', default: OPERATION.CREATE }) @Column('varchar', { name: 'process', default: OPERATION.CREATE })
process: OPERATION; process: OPERATION;
@Column('json', { name: 'data', nullable: true }) @Column('json', { name: 'data', nullable: true })
data: any; data: any;
@Column('json', { name: 'old_data', nullable: true }) @Column('json', { name: 'old_data', nullable: true })
old_data: any; old_data: any;
@Column('bigint', { name: 'created_at', nullable: true }) @Column('bigint', { name: 'created_at', nullable: true })
created_at: number; created_at: number;
@Column('varchar', { name: 'creator_name', nullable: true }) @Column('varchar', { name: 'creator_name', nullable: true })
creator_name: string; creator_name: string;
@Column('varchar', { name: 'creator_id', nullable: true }) @Column('varchar', { name: 'creator_id', nullable: true })
creator_id: string; creator_id: string;
} }

View File

@ -1,17 +1,17 @@
import { BaseDataService } from "src/core/modules/data/service/base-data.service"; import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
import { ErrorLogEntity } from "../../domain/entities/error-log.entity"; import { ErrorLogEntity } from '../../domain/entities/error-log.entity';
import { Injectable } from "@nestjs/common"; import { Injectable } from '@nestjs/common';
import { InjectRepository } from "@nestjs/typeorm"; import { InjectRepository } from '@nestjs/typeorm';
import { ErrorLogModel } from "../models/error-log.model"; import { ErrorLogModel } from '../models/error-log.model';
import { Repository } from "typeorm"; import { Repository } from 'typeorm';
import { CONNECTION_NAME } from "src/core/strings/constants/base.constants"; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
@Injectable() @Injectable()
export class ErrorLogService extends BaseDataService<ErrorLogEntity> { export class ErrorLogService extends BaseDataService<ErrorLogEntity> {
constructor( constructor(
@InjectRepository(ErrorLogModel, CONNECTION_NAME.DEFAULT) @InjectRepository(ErrorLogModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<ErrorLogModel>, private repo: Repository<ErrorLogModel>,
) { ) {
super(repo); super(repo);
} }
} }

View File

@ -1,17 +1,17 @@
import { Injectable } from "@nestjs/common"; import { Injectable } from '@nestjs/common';
import { BaseDataService } from "src/core/modules/data/service/base-data.service"; import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
import { LogEntity } from "../../domain/entities/log.entity"; import { LogEntity } from '../../domain/entities/log.entity';
import { LogModel } from "../models/log.model"; import { LogModel } from '../models/log.model';
import { InjectRepository } from "@nestjs/typeorm"; import { InjectRepository } from '@nestjs/typeorm';
import { CONNECTION_NAME } from "src/core/strings/constants/base.constants"; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { Repository } from "typeorm"; import { Repository } from 'typeorm';
@Injectable() @Injectable()
export class LogService extends BaseDataService<LogEntity> { export class LogService extends BaseDataService<LogEntity> {
constructor( constructor(
@InjectRepository(LogModel, CONNECTION_NAME.DEFAULT) @InjectRepository(LogModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<LogModel>, private repo: Repository<LogModel>,
) { ) {
super(repo); super(repo);
} }
} }

View File

@ -1,12 +1,12 @@
import { BaseCoreEntity } from "src/core/modules/domain/entities/base-core.entity"; import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
export interface ErrorLogEntity extends BaseCoreEntity { export interface ErrorLogEntity extends BaseCoreEntity {
data_id: string; data_id: string;
message: string; message: string;
description: string; description: string;
module: string; module: string;
sub_module: string; sub_module: string;
created_at: number; created_at: number;
creator_name: string; creator_name: string;
creator_id: string; creator_id: string;
} }

View File

@ -1,5 +1,5 @@
import { IEvent } from "src/core/strings/constants/interface.constants"; import { IEvent } from 'src/core/strings/constants/interface.constants';
export class RecordErrorLog { export class RecordErrorLog {
constructor(public readonly data: IEvent) {} constructor(public readonly data: IEvent) {}
} }

View File

@ -1,15 +1,15 @@
import { BaseCoreEntity } from "src/core/modules/domain/entities/base-core.entity"; import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
import { OPERATION } from "src/core/strings/constants/base.constants"; import { OPERATION } from 'src/core/strings/constants/base.constants';
export interface LogEntity extends BaseCoreEntity { export interface LogEntity extends BaseCoreEntity {
data_id: string; data_id: string;
process: OPERATION; process: OPERATION;
data: any; data: any;
old_data: any; old_data: any;
description: string; description: string;
module: string; module: string;
sub_module: string; sub_module: string;
created_at: number; created_at: number;
creator_name: string; creator_name: string;
creator_id: string; creator_id: string;
} }

View File

@ -1,5 +1,5 @@
import { IEvent } from "src/core/strings/constants/interface.constants"; import { IEvent } from 'src/core/strings/constants/interface.constants';
export class RecordLog { export class RecordLog {
constructor(public readonly data: IEvent) {} constructor(public readonly data: IEvent) {}
} }

View File

@ -1,11 +1,11 @@
import { EventsHandler, IEventHandler } from "@nestjs/cqrs"; import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { RecordErrorLog } from "../entities/error-log.event"; import { RecordErrorLog } from '../entities/error-log.event';
import { ErrorLogService } from '../../data/services/error-log.service';
@EventsHandler(RecordErrorLog) @EventsHandler(RecordErrorLog)
export class RecordErrorLogHandler implements IEventHandler<RecordErrorLog> { export class RecordErrorLogHandler implements IEventHandler<RecordErrorLog> {
constructor(private dataservice: ErrorLogService) {}
async handle(event: RecordErrorLog) {
console.log(event, 'das error') async handle(event: RecordErrorLog) {
} }
}
}

View File

@ -1,11 +1,8 @@
import { EventsHandler, IEventHandler } from "@nestjs/cqrs"; import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { RecordLog } from "../entities/log.event"; import { RecordLog } from '../entities/log.event';
@EventsHandler(RecordLog) @EventsHandler(RecordLog)
export class RecordLogHandler implements IEventHandler<RecordLog> { export class RecordLogHandler implements IEventHandler<RecordLog> {
async handle(event: RecordLog) {
async handle(event: RecordLog) { }
console.log(event, 'log') }
}
}

View File

@ -1,28 +1,31 @@
import { Module } from "@nestjs/common"; import { Module } from '@nestjs/common';
import { ConfigModule } from "@nestjs/config"; import { ConfigModule } from '@nestjs/config';
import { CqrsModule } from "@nestjs/cqrs"; import { CqrsModule } from '@nestjs/cqrs';
import { TypeOrmModule } from "@nestjs/typeorm"; import { TypeOrmModule } from '@nestjs/typeorm';
import { LogModel } from "./data/models/log.model"; import { LogModel } from './data/models/log.model';
import { ErrorLogModel } from "./data/models/error-log.model"; import { ErrorLogModel } from './data/models/error-log.model';
import { CONNECTION_NAME } from "src/core/strings/constants/base.constants"; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { RecordErrorLogHandler } from "./domain/handlers/error-log.handler"; import { RecordErrorLogHandler } from './domain/handlers/error-log.handler';
import { RecordLogHandler } from "./domain/handlers/log.handler"; import { RecordLogHandler } from './domain/handlers/log.handler';
import { ErrorLogService } from "./data/services/error-log.service"; import { ErrorLogService } from './data/services/error-log.service';
import { LogService } from "./data/services/log.service"; import { LogService } from './data/services/log.service';
@Module({ @Module({
imports: [ imports: [
ConfigModule.forRoot(), ConfigModule.forRoot(),
TypeOrmModule.forFeature([LogModel, ErrorLogModel], CONNECTION_NAME.DEFAULT), TypeOrmModule.forFeature(
CqrsModule, [LogModel, ErrorLogModel],
], CONNECTION_NAME.DEFAULT,
controllers: [], ),
providers: [ CqrsModule,
RecordLogHandler, ],
RecordErrorLogHandler, controllers: [],
providers: [
RecordLogHandler,
RecordErrorLogHandler,
LogService, LogService,
ErrorLogService, ErrorLogService,
], ],
}) })
export class LogModule {} export class LogModule {}

View File

@ -1,4 +1,4 @@
import { IEvent } from '@nestjs/cqrs'; import { IEvent } from 'src/core/strings/constants/interface.constants';
export class UserPrivilegeChangeStatusEvent { export class UserPrivilegeChangeStatusEvent {
constructor(public readonly data: IEvent) {} constructor(public readonly data: IEvent) {}

View File

@ -16,7 +16,10 @@ export class UserPrivilegeConfigurationDataOrchestrator {
async update(data): Promise<UserPrivilegeConfigurationEntity> { async update(data): Promise<UserPrivilegeConfigurationEntity> {
this.updateManager.setData(data); this.updateManager.setData(data);
this.updateManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE_CONFIGURATION); this.updateManager.setService(
this.serviceData,
TABLE_NAME.USER_PRIVILEGE_CONFIGURATION,
);
await this.updateManager.execute(); await this.updateManager.execute();
return this.updateManager.getResult(); return this.updateManager.getResult();
} }

View File

@ -58,7 +58,10 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat
async batchDelete(dataIds: string[]): Promise<BatchResult> { async batchDelete(dataIds: string[]): Promise<BatchResult> {
this.batchDeleteManager.setData(dataIds); this.batchDeleteManager.setData(dataIds);
this.batchDeleteManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); this.batchDeleteManager.setService(
this.serviceData,
TABLE_NAME.USER_PRIVILEGE,
);
await this.batchDeleteManager.execute(); await this.batchDeleteManager.execute();
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
@ -72,7 +75,10 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat
async batchActive(dataIds: string[]): Promise<BatchResult> { async batchActive(dataIds: string[]): Promise<BatchResult> {
this.batchActiveManager.setData(dataIds, STATUS.ACTIVE); this.batchActiveManager.setData(dataIds, STATUS.ACTIVE);
this.batchActiveManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); this.batchActiveManager.setService(
this.serviceData,
TABLE_NAME.USER_PRIVILEGE,
);
await this.batchActiveManager.execute(); await this.batchActiveManager.execute();
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
@ -86,21 +92,30 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat
async batchConfirm(dataIds: string[]): Promise<BatchResult> { async batchConfirm(dataIds: string[]): Promise<BatchResult> {
this.batchConfirmManager.setData(dataIds, STATUS.ACTIVE); this.batchConfirmManager.setData(dataIds, STATUS.ACTIVE);
this.batchConfirmManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); this.batchConfirmManager.setService(
this.serviceData,
TABLE_NAME.USER_PRIVILEGE,
);
await this.batchConfirmManager.execute(); await this.batchConfirmManager.execute();
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId): Promise<String> { async inactive(dataId): Promise<String> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); this.inactiveManager.setService(
this.serviceData,
TABLE_NAME.USER_PRIVILEGE,
);
await this.inactiveManager.execute(); await this.inactiveManager.execute();
return this.inactiveManager.getResult(); return this.inactiveManager.getResult();
} }
async batchInactive(dataIds: string[]): Promise<BatchResult> { async batchInactive(dataIds: string[]): Promise<BatchResult> {
this.batchInactiveManager.setData(dataIds, STATUS.INACTIVE); this.batchInactiveManager.setData(dataIds, STATUS.INACTIVE);
this.batchInactiveManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE); this.batchInactiveManager.setService(
this.serviceData,
TABLE_NAME.USER_PRIVILEGE,
);
await this.batchInactiveManager.execute(); await this.batchInactiveManager.execute();
return this.batchInactiveManager.getResult(); return this.batchInactiveManager.getResult();
} }