feat(SPG-125) wip Logging
parent
cefff6d5c7
commit
f36e3b26d4
|
@ -1,6 +1,5 @@
|
||||||
import { Module, Scope } from '@nestjs/common';
|
import { Module, Scope } from '@nestjs/common';
|
||||||
import { RefreshTokenInterceptor, SessionModule } from './core/sessions';
|
import { RefreshTokenInterceptor, SessionModule } from './core/sessions';
|
||||||
import { JWTGuard } from './core/guards';
|
|
||||||
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
|
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
|
||||||
import { HttpExceptionFilter, TransformInterceptor } from './core/response';
|
import { HttpExceptionFilter, TransformInterceptor } from './core/response';
|
||||||
import { ApmModule } from './core/apm';
|
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 { UserModel } from './modules/user-related/user/data/models/user.model';
|
||||||
import { AuthModule } from './modules/configuration/auth/auth.module';
|
import { AuthModule } from './modules/configuration/auth/auth.module';
|
||||||
import { UserModule } from './modules/user-related/user/user.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({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -31,13 +33,19 @@ import { UserModule } from './modules/user-related/user/user.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: [...UserPrivilegeModels, UserModel],
|
entities: [
|
||||||
|
...UserPrivilegeModels,
|
||||||
|
UserModel,
|
||||||
|
LogModel,
|
||||||
|
ErrorLogModel,
|
||||||
|
],
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
}),
|
}),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
SessionModule,
|
SessionModule,
|
||||||
AuthModule,
|
AuthModule,
|
||||||
CouchModule,
|
CouchModule,
|
||||||
|
LogModule,
|
||||||
|
|
||||||
UserModule,
|
UserModule,
|
||||||
UserPrivilegeModule,
|
UserPrivilegeModule,
|
||||||
|
|
|
@ -3,14 +3,16 @@ import { EventBus } from '@nestjs/cqrs';
|
||||||
import { UserProvider, UsersSession } from 'src/core/sessions';
|
import { UserProvider, UsersSession } from 'src/core/sessions';
|
||||||
import { BLANK_USER } from 'src/core/strings/constants/base.constants';
|
import { BLANK_USER } from 'src/core/strings/constants/base.constants';
|
||||||
import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { QueryRunner } from 'typeorm';
|
import { QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export abstract class BaseManager {
|
export abstract class BaseManager {
|
||||||
public user: UsersSession;
|
public user: UsersSession;
|
||||||
public queryRunner: QueryRunner;
|
|
||||||
public dataService: any;
|
public dataService: any;
|
||||||
protected data: any;
|
protected data: any;
|
||||||
|
public queryRunner: QueryRunner;
|
||||||
|
protected tableName: TABLE_NAME;
|
||||||
@Inject()
|
@Inject()
|
||||||
protected userProvider: UserProvider;
|
protected userProvider: UserProvider;
|
||||||
@Inject()
|
@Inject()
|
||||||
|
@ -26,11 +28,12 @@ export abstract class BaseManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setService(dataService) {
|
setService(dataService, tableName) {
|
||||||
this.dataService = dataService;
|
this.dataService = dataService;
|
||||||
|
this.tableName = tableName;
|
||||||
this.queryRunner = this.dataService
|
this.queryRunner = this.dataService
|
||||||
.getRepository()
|
.getRepository()
|
||||||
.manager.connection.createQueryRunner();
|
.manager.connection.createQueryRunner(tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract get eventTopics(): EventTopics[];
|
abstract get eventTopics(): EventTopics[];
|
||||||
|
@ -62,8 +65,6 @@ export abstract class BaseManager {
|
||||||
this.baseLog.verbose('commitTransaction');
|
this.baseLog.verbose('commitTransaction');
|
||||||
await this.queryRunner.commitTransaction();
|
await this.queryRunner.commitTransaction();
|
||||||
|
|
||||||
this.publishEvents();
|
|
||||||
|
|
||||||
await this.queryRunner.release();
|
await this.queryRunner.release();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.response) throw new Error(JSON.stringify(e.response));
|
if (e.response) throw new Error(JSON.stringify(e.response));
|
||||||
|
@ -80,8 +81,4 @@ export abstract class BaseManager {
|
||||||
abstract process(): Promise<void>;
|
abstract process(): Promise<void>;
|
||||||
|
|
||||||
abstract afterProcess(): Promise<void>;
|
abstract afterProcess(): Promise<void>;
|
||||||
|
|
||||||
async publishEvents() {
|
|
||||||
if (!this.eventTopics.length) return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { CheckDuplicateHelper } from 'src/core/helpers/query/check-duplicate.helpers';
|
import { CheckDuplicateHelper } from 'src/core/helpers/query/check-duplicate.helpers';
|
||||||
import { BaseManager } from '../base.manager';
|
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<Entity> extends BaseManager {
|
export abstract class BaseCreateManager<Entity> extends BaseManager {
|
||||||
protected result: Entity;
|
protected result: Entity;
|
||||||
|
@ -37,6 +39,8 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
|
||||||
this.entityTarget,
|
this.entityTarget,
|
||||||
this.data,
|
this.data,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.publishEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getResult(): Promise<Entity> {
|
async getResult(): Promise<Entity> {
|
||||||
|
@ -46,4 +50,21 @@ export abstract class BaseCreateManager<Entity> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,18 @@ import {
|
||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
import { EventBus } from '@nestjs/cqrs';
|
||||||
import { Response } from 'express';
|
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()
|
@Catch()
|
||||||
export class HttpExceptionFilter implements ExceptionFilter {
|
export class HttpExceptionFilter implements ExceptionFilter {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private eventBus: EventBus,
|
||||||
|
) {}
|
||||||
|
|
||||||
catch(exception: any, host: ArgumentsHost) {
|
catch(exception: any, host: ArgumentsHost) {
|
||||||
const ctx = host.switchToHttp();
|
const ctx = host.switchToHttp();
|
||||||
const response = ctx.getResponse<Response>();
|
const response = ctx.getResponse<Response>();
|
||||||
|
@ -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);
|
response.status(status).json(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
export enum TABLE_NAME {
|
export enum TABLE_NAME {
|
||||||
|
LOG = 'logs',
|
||||||
|
ERROR_LOG = 'log_errors',
|
||||||
USER = 'users',
|
USER = 'users',
|
||||||
USER_PRIVILEGE = 'user_privileges',
|
USER_PRIVILEGE = 'user_privileges',
|
||||||
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
|
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||||
import { UserDataService } from 'src/modules/user-related/user/data/services.ts/user-data.service';
|
import { UserDataService } from 'src/modules/user-related/user/data/services.ts/user-data.service';
|
||||||
import { LoginManager } from './managers/login.manager';
|
import { LoginManager } from './managers/login.manager';
|
||||||
import { LogoutManager } from './managers/logout.manager';
|
import { LogoutManager } from './managers/logout.manager';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthOrchestrator {
|
export class AuthOrchestrator {
|
||||||
|
@ -13,13 +14,13 @@ export class AuthOrchestrator {
|
||||||
|
|
||||||
async login(data): Promise<any> {
|
async login(data): Promise<any> {
|
||||||
this.loginManager.setData(data);
|
this.loginManager.setData(data);
|
||||||
this.loginManager.setService(this.serviceData);
|
this.loginManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||||
await this.loginManager.execute();
|
await this.loginManager.execute();
|
||||||
return this.loginManager.getResult();
|
return this.loginManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
async logout(): Promise<any> {
|
async logout(): Promise<any> {
|
||||||
this.logoutManager.setService(this.serviceData);
|
this.logoutManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||||
await this.logoutManager.execute();
|
await this.logoutManager.execute();
|
||||||
return this.logoutManager.getResult();
|
return this.logoutManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
import { ConfigModule } from "@nestjs/config";
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { CouchDataController } from "./infrastructure/couch.controller";
|
import { CouchDataController } from './infrastructure/couch.controller';
|
||||||
import { Module } from "@nestjs/common";
|
import { Module } from '@nestjs/common';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
// TypeOrmModule.forFeature([UserPrivilegeModel], CONNECTION_NAME.DEFAULT),
|
// TypeOrmModule.forFeature([UserPrivilegeModel], CONNECTION_NAME.DEFAULT),
|
||||||
// CqrsModule,
|
// CqrsModule,
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [CouchDataController],
|
||||||
CouchDataController
|
providers: [],
|
||||||
],
|
})
|
||||||
providers: [
|
export class CouchModule {}
|
||||||
],
|
|
||||||
})
|
|
||||||
export class CouchModule {}
|
|
||||||
|
|
|
@ -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 { ApiTags } from '@nestjs/swagger';
|
||||||
import { Unprotected } from "src/core/guards";
|
import { Unprotected } from 'src/core/guards';
|
||||||
import * as Nano from 'nano'
|
import * as Nano from 'nano';
|
||||||
import { CreateUserPrivilegeDto } from "src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto";
|
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
|
||||||
|
|
||||||
@ApiTags(`couch`)
|
@ApiTags(`couch`)
|
||||||
@Controller('couch')
|
@Controller('couch')
|
||||||
@Unprotected()
|
@Unprotected()
|
||||||
export class CouchDataController {
|
export class CouchDataController {
|
||||||
|
@Post()
|
||||||
@Post()
|
async createDoc(@Body() entity: CreateUserPrivilegeDto) {
|
||||||
async createDoc(
|
try {
|
||||||
@Body() entity: CreateUserPrivilegeDto
|
let n = Nano('http://admin:secret@127.0.0.1:5984');
|
||||||
) {
|
let db = await n.db.create(entity.name);
|
||||||
try {
|
} catch (error) {
|
||||||
let n = Nano('http://admin:secret@127.0.0.1:5984')
|
console.log(error, 'dsa');
|
||||||
let db = await n.db.create(entity.name)
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error, 'dsa')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Post('doc')
|
@Post('doc')
|
||||||
async createDocs(
|
async createDocs(@Body() entity: CreateUserPrivilegeDto) {
|
||||||
@Body() entity: CreateUserPrivilegeDto
|
try {
|
||||||
) {
|
const nano = require('nano')('http://admin:secret@127.0.0.1:5984');
|
||||||
try {
|
const people = nano.db.use('string');
|
||||||
const nano = require("nano")("http://admin:secret@127.0.0.1:5984");
|
console.log(await people.info());
|
||||||
const people = nano.db.use('string');
|
const data = {
|
||||||
console.log(await people.info())
|
id: '1212',
|
||||||
const data = {
|
name: 'dsadas',
|
||||||
id: '1212',
|
};
|
||||||
name: 'dsadas'
|
// await people.insert(data)
|
||||||
}
|
|
||||||
// await people.insert(data)
|
|
||||||
|
|
||||||
people.changesReader.start()
|
people.changesReader
|
||||||
.on('change', (change) => { console.log(change) })
|
.start()
|
||||||
.on('batch', (b) => {
|
.on('change', (change) => {
|
||||||
console.log('a batch of', b.length, 'changes has arrived');
|
console.log(change);
|
||||||
}).on('seq', (s) => {
|
})
|
||||||
console.log('sequence token', s);
|
.on('batch', (b) => {
|
||||||
}).on('error', (e) => {
|
console.log('a batch of', b.length, 'changes has arrived');
|
||||||
console.error('error', e);
|
})
|
||||||
})
|
.on('seq', (s) => {
|
||||||
|
console.log('sequence token', s);
|
||||||
} catch (error) {
|
})
|
||||||
console.log(error, 'dsa')
|
.on('error', (e) => {
|
||||||
}
|
console.error('error', e);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error, 'dsa');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async getDoc(
|
async getDoc() {
|
||||||
) {
|
try {
|
||||||
try {
|
let n = Nano('http://admin:secret@127.0.0.1:5984');
|
||||||
let n = Nano('http://admin:secret@127.0.0.1:5984')
|
const people = n.use('string');
|
||||||
const people = n.use('string');
|
|
||||||
|
|
||||||
// return people.get();
|
// return people.get();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error, 'dsa')
|
console.log(error, 'dsa');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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<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;
|
||||||
|
}
|
|
@ -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<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;
|
||||||
|
}
|
|
@ -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<ErrorLogEntity> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(ErrorLogModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<ErrorLogModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<LogEntity> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(LogModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<LogModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { IEvent } from "src/core/strings/constants/interface.constants";
|
||||||
|
|
||||||
|
export class RecordErrorLog {
|
||||||
|
constructor(public readonly data: IEvent) {}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { IEvent } from "src/core/strings/constants/interface.constants";
|
||||||
|
|
||||||
|
export class RecordLog {
|
||||||
|
constructor(public readonly data: IEvent) {}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { EventsHandler, IEventHandler } from "@nestjs/cqrs";
|
||||||
|
import { RecordErrorLog } from "../entities/error-log.event";
|
||||||
|
|
||||||
|
@EventsHandler(RecordErrorLog)
|
||||||
|
export class RecordErrorLogHandler implements IEventHandler<RecordErrorLog> {
|
||||||
|
|
||||||
|
async handle(event: RecordErrorLog) {
|
||||||
|
console.log(event, 'das error')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
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')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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 {}
|
|
@ -16,7 +16,7 @@ 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);
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { BatchConfirmUserPrivilegeManager } from './managers/batch-confirm-user-
|
||||||
import { BatchInactiveUserPrivilegeManager } from './managers/batch-inactive-user-privilege.manager';
|
import { BatchInactiveUserPrivilegeManager } from './managers/batch-inactive-user-privilege.manager';
|
||||||
import { BatchActiveUserPrivilegeManager } from './managers/batch-active-user-privilege.manager';
|
import { BatchActiveUserPrivilegeManager } from './managers/batch-active-user-privilege.manager';
|
||||||
import { BatchDeleteUserPrivilegeManager } from './managers/batch-delete-user-privilege.manager';
|
import { BatchDeleteUserPrivilegeManager } from './managers/batch-delete-user-privilege.manager';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrator<UserPrivilegeEntity> {
|
export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrator<UserPrivilegeEntity> {
|
||||||
|
@ -35,7 +36,7 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat
|
||||||
|
|
||||||
async create(data): Promise<UserPrivilegeEntity> {
|
async create(data): Promise<UserPrivilegeEntity> {
|
||||||
this.createManager.setData(data);
|
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.execute();
|
||||||
await this.createManager.generateConfig();
|
await this.createManager.generateConfig();
|
||||||
return this.createManager.getResult();
|
return this.createManager.getResult();
|
||||||
|
@ -43,63 +44,63 @@ export class UserPrivilegeDataOrchestrator extends BaseDataTransactionOrchestrat
|
||||||
|
|
||||||
async update(dataId, data): Promise<UserPrivilegeEntity> {
|
async update(dataId, data): Promise<UserPrivilegeEntity> {
|
||||||
this.updateManager.setData(dataId, data);
|
this.updateManager.setData(dataId, data);
|
||||||
this.updateManager.setService(this.serviceData);
|
this.updateManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE);
|
||||||
await this.updateManager.execute();
|
await this.updateManager.execute();
|
||||||
return this.updateManager.getResult();
|
return this.updateManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(dataId): Promise<String> {
|
async delete(dataId): Promise<String> {
|
||||||
this.deleteManager.setData(dataId);
|
this.deleteManager.setData(dataId);
|
||||||
this.deleteManager.setService(this.serviceData);
|
this.deleteManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE);
|
||||||
await this.deleteManager.execute();
|
await this.deleteManager.execute();
|
||||||
return this.deleteManager.getResult();
|
return this.deleteManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
async active(dataId): Promise<String> {
|
async active(dataId): Promise<String> {
|
||||||
this.activeManager.setData(dataId, STATUS.ACTIVE);
|
this.activeManager.setData(dataId, STATUS.ACTIVE);
|
||||||
this.activeManager.setService(this.serviceData);
|
this.activeManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE);
|
||||||
await this.activeManager.execute();
|
await this.activeManager.execute();
|
||||||
return this.activeManager.getResult();
|
return this.activeManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
async confirm(dataId): Promise<String> {
|
async confirm(dataId): Promise<String> {
|
||||||
this.confirmManager.setData(dataId, STATUS.ACTIVE);
|
this.confirmManager.setData(dataId, STATUS.ACTIVE);
|
||||||
this.confirmManager.setService(this.serviceData);
|
this.confirmManager.setService(this.serviceData, TABLE_NAME.USER_PRIVILEGE);
|
||||||
await this.confirmManager.execute();
|
await this.confirmManager.execute();
|
||||||
return this.confirmManager.getResult();
|
return this.confirmManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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);
|
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);
|
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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue