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,
password: process.env.DEFAULT_DB_PASS,
database: process.env.DEFAULT_DB_NAME,
entities: [
...UserPrivilegeModels,
UserModel,
LogModel,
ErrorLogModel,
],
entities: [...UserPrivilegeModels, UserModel, LogModel, ErrorLogModel],
synchronize: false,
}),
CqrsModule,

View File

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

View File

@ -7,15 +7,13 @@ import {
} from '@nestjs/common';
import { EventBus } from '@nestjs/cqrs';
import { Response } from 'express';
import { apm } from 'src/core/apm';
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,
) {}
constructor(private eventBus: EventBus) {}
catch(exception: any, host: ArgumentsHost) {
const ctx = host.switchToHttp();
@ -49,17 +47,17 @@ export class HttpExceptionFilter implements ExceptionFilter {
};
}
this.eventBus.publish(
new RecordErrorLog({
id: '',
old: null,
data: null,
user: null,
description: '',
module: null,
op: OPERATION.CREATE,
})
)
// this.eventBus.publish(
// new RecordErrorLog({
// id: '',
// old: null,
// data: null,
// user: null,
// description: '',
// module: null,
// op: OPERATION.CREATE,
// }),
// );
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,
password: process.env.DEFAULT_DB_PASS,
database: process.env.DEFAULT_DB_NAME,
entities: ['src/modules/user-related/**/data/models/*.ts'],
entities: ['src/modules/**/**/data/models/*.ts'],
migrationsTableName: 'migrations',
migrations: ['src/database/migrations/*.ts'],
synchronize: false,

View File

@ -1,29 +1,34 @@
import { BaseCoreModel } from "src/core/modules/data/model/base-core.model";
import { ErrorLogEntity } from "../../domain/entities/error-log.entity";
import { Column } from "typeorm";
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
import { ErrorLogEntity } from '../../domain/entities/error-log.entity';
import { Column, Entity } from 'typeorm';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
export class ErrorLogModel extends BaseCoreModel<ErrorLogEntity> 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;
}
@Entity(TABLE_NAME.ERROR_LOG)
export class ErrorLogModel
extends BaseCoreModel<ErrorLogEntity>
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;
}

View File

@ -1,38 +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";
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<LogEntity> 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;
}
@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;
}

View File

@ -1,17 +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";
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<ErrorLogEntity> {
constructor(
@InjectRepository(ErrorLogModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<ErrorLogModel>,
) {
super(repo);
}
}
constructor(
@InjectRepository(ErrorLogModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<ErrorLogModel>,
) {
super(repo);
}
}

View File

@ -1,17 +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";
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<LogEntity> {
constructor(
@InjectRepository(LogModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<LogModel>,
) {
super(repo);
}
}
constructor(
@InjectRepository(LogModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<LogModel>,
) {
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 {
data_id: string;
message: string;
description: string;
module: string;
sub_module: string;
created_at: number;
creator_name: string;
creator_id: string;
}
data_id: string;
message: string;
description: string;
module: string;
sub_module: string;
created_at: number;
creator_name: 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 {
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 { OPERATION } from "src/core/strings/constants/base.constants";
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;
}
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;
}

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 {
constructor(public readonly data: IEvent) {}
}
constructor(public readonly data: IEvent) {}
}

View File

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

View File

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

View File

@ -1,28 +1,31 @@
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";
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,
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forFeature(
[LogModel, ErrorLogModel],
CONNECTION_NAME.DEFAULT,
),
CqrsModule,
],
controllers: [],
providers: [
RecordLogHandler,
RecordErrorLogHandler,
LogService,
ErrorLogService,
],
LogService,
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 {
constructor(public readonly data: IEvent) {}

View File

@ -16,7 +16,10 @@ export class UserPrivilegeConfigurationDataOrchestrator {
async update(data): Promise<UserPrivilegeConfigurationEntity> {
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();
return this.updateManager.getResult();
}

View File

@ -58,7 +58,10 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat
async batchDelete(dataIds: string[]): Promise<BatchResult> {
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();
return this.batchDeleteManager.getResult();
}
@ -72,7 +75,10 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat
async batchActive(dataIds: string[]): Promise<BatchResult> {
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();
return this.batchActiveManager.getResult();
}
@ -86,21 +92,30 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat
async batchConfirm(dataIds: string[]): Promise<BatchResult> {
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();
return this.batchConfirmManager.getResult();
}
async inactive(dataId): Promise<String> {
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();
return this.inactiveManager.getResult();
}
async batchInactive(dataIds: string[]): Promise<BatchResult> {
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();
return this.batchInactiveManager.getResult();
}