@estgbue/mezgeb 0.0.41 → 0.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/mezgeb/client/client-audit.interceptor.js +6 -5
- package/dist/mezgeb/client/client-save-update.d.ts +3 -0
- package/dist/mezgeb/client/client-save-update.d.ts.map +1 -0
- package/dist/mezgeb/client/client-save-update.js +18 -0
- package/dist/mezgeb/client/client.subscriber.d.ts +3 -2
- package/dist/mezgeb/client/client.subscriber.d.ts.map +1 -1
- package/dist/mezgeb/client/client.subscriber.js +26 -8
- package/dist/mezgeb/listener/controllers/audit-log-command.controller.d.ts +3 -3
- package/dist/mezgeb/listener/controllers/audit-log-command.controller.d.ts.map +1 -1
- package/dist/mezgeb/listener/controllers/audit-log-command.controller.js +2 -2
- package/dist/mezgeb/listener/services/audit-log-command.service.d.ts +4 -5
- package/dist/mezgeb/listener/services/audit-log-command.service.d.ts.map +1 -1
- package/dist/mezgeb/listener/services/audit-log-command.service.js +34 -67
- package/dist/mezgeb/mezgeb.dto.d.ts +9 -0
- package/dist/mezgeb/mezgeb.dto.d.ts.map +1 -1
- package/dist/mezgeb/mezgeb.dto.js +4 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './mezgeb/client/client-audit.interceptor';
|
|
2
2
|
export * from './mezgeb/client/client.module';
|
|
3
|
+
export * from './mezgeb/client/client.logger.config';
|
|
4
|
+
export * from './mezgeb/client/client-save-update';
|
|
3
5
|
export * from './mezgeb.module';
|
|
4
6
|
export * from './mezgeb/listener/audit.module';
|
|
5
7
|
export * from './mezgeb/listener/dtos/audit.dto';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../libs/mezgeb/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0CAA0C,CAAC;AACzD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AACjD,cAAc,sDAAsD,CAAC;AACrE,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../libs/mezgeb/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0CAA0C,CAAC;AACzD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AACjD,cAAc,sDAAsD,CAAC;AACrE,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./mezgeb/client/client-audit.interceptor"), exports);
|
|
18
18
|
__exportStar(require("./mezgeb/client/client.module"), exports);
|
|
19
|
+
__exportStar(require("./mezgeb/client/client.logger.config"), exports);
|
|
20
|
+
__exportStar(require("./mezgeb/client/client-save-update"), exports);
|
|
19
21
|
__exportStar(require("./mezgeb.module"), exports);
|
|
20
22
|
__exportStar(require("./mezgeb/listener/audit.module"), exports);
|
|
21
23
|
__exportStar(require("./mezgeb/listener/dtos/audit.dto"), exports);
|
|
@@ -61,7 +61,7 @@ let ClientLoggerInterceptor = class ClientLoggerInterceptor {
|
|
|
61
61
|
}));
|
|
62
62
|
}
|
|
63
63
|
handleRequestAuditInitiation(context, next, requestId) {
|
|
64
|
-
var _a, _b;
|
|
64
|
+
var _a, _b, _c, _d, _e;
|
|
65
65
|
const req = context.switchToHttp().getRequest();
|
|
66
66
|
const { ip, ips, method, originalUrl, headers, body, params, user } = req;
|
|
67
67
|
const ds = this.connection;
|
|
@@ -69,8 +69,8 @@ let ClientLoggerInterceptor = class ClientLoggerInterceptor {
|
|
|
69
69
|
const log = {
|
|
70
70
|
id: requestId,
|
|
71
71
|
requestMethod: method,
|
|
72
|
-
application: process.env.APPLICATION_NAME,
|
|
73
|
-
module: originalUrl.split('/')[2],
|
|
72
|
+
application: (_d = (_c = process.env.APPLICATION_NAME) !== null && _c !== void 0 ? _c : process.env.APP_NAME) !== null && _d !== void 0 ? _d : 'DEFAULT',
|
|
73
|
+
module: (_e = originalUrl.split('/')[2]) !== null && _e !== void 0 ? _e : 'DEFAULT',
|
|
74
74
|
requestBody: originalUrl.includes('/auth') ? {} : body,
|
|
75
75
|
requestHeader: this.mapHeaders(headers),
|
|
76
76
|
statusCode: 201,
|
|
@@ -81,6 +81,7 @@ let ClientLoggerInterceptor = class ClientLoggerInterceptor {
|
|
|
81
81
|
this.rmsRMQClient.emit(mezgeb_enum_1.RegisterRequestAudit, log);
|
|
82
82
|
}
|
|
83
83
|
handleEventAuditInitiation(context, next, requestId) {
|
|
84
|
+
var _a, _b;
|
|
84
85
|
const eventPayload = context.getArgs()[0];
|
|
85
86
|
const eventPattern = context.getArgs()[1].args[2];
|
|
86
87
|
const ds = this.connection;
|
|
@@ -88,8 +89,8 @@ let ClientLoggerInterceptor = class ClientLoggerInterceptor {
|
|
|
88
89
|
const log = {
|
|
89
90
|
id: requestId,
|
|
90
91
|
requestMethod: mezgeb_enum_1.EAuditLogRequestMethod.EVENT,
|
|
91
|
-
application: process.env.APPLICATION_NAME,
|
|
92
|
-
module: eventPattern,
|
|
92
|
+
application: (_b = (_a = process.env.APPLICATION_NAME) !== null && _a !== void 0 ? _a : process.env.APP_NAME) !== null && _b !== void 0 ? _b : 'DEFAULT',
|
|
93
|
+
module: eventPattern !== null && eventPattern !== void 0 ? eventPattern : 'DEFAULT',
|
|
93
94
|
requestBody: eventPayload,
|
|
94
95
|
requestHeader: {},
|
|
95
96
|
statusCode: 201,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-save-update.d.ts","sourceRoot":"","sources":["../../../libs/mezgeb/src/mezgeb/client/client-save-update.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,QAAQ,GAAU,CAAC,SAAS,aAAa,EACpD,MAAM,UAAU,CAAC,CAAC,CAAC,EACnB,YAAY,gBAAgB,CAAC,CAAC,CAAC,EAC/B,OAAO,OAAO,CAAC,CAAC,CAAC,KAChB,OAAO,CAAC,CAAC,CAMX,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.safeSave = void 0;
|
|
13
|
+
const safeSave = (repo, conditions, patch) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const entity = yield repo.findOneByOrFail(conditions);
|
|
15
|
+
Object.assign(entity, patch);
|
|
16
|
+
return repo.save(entity);
|
|
17
|
+
});
|
|
18
|
+
exports.safeSave = safeSave;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ClientProxy } from '@nestjs/microservices';
|
|
2
|
-
import {
|
|
2
|
+
import { DataSource, EntitySubscriberInterface, InsertEvent, RemoveEvent, UpdateEvent } from 'typeorm';
|
|
3
3
|
export declare class ClientSubscriber implements EntitySubscriberInterface {
|
|
4
4
|
private readonly dataSource;
|
|
5
5
|
private readonly rmsRMQClient;
|
|
6
6
|
constructor(dataSource: DataSource, rmsRMQClient: ClientProxy);
|
|
7
7
|
afterInsert(event: InsertEvent<any>): Promise<any> | void;
|
|
8
|
-
|
|
8
|
+
afterUpdate(event: UpdateEvent<any>): Promise<any> | void;
|
|
9
|
+
afterRemove(event: RemoveEvent<any>): Promise<any> | void;
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=client.subscriber.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.subscriber.d.ts","sourceRoot":"","sources":["../../../libs/mezgeb/src/mezgeb/client/client.subscriber.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"client.subscriber.d.ts","sourceRoot":"","sources":["../../../libs/mezgeb/src/mezgeb/client/client.subscriber.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,UAAU,EACV,yBAAyB,EAEzB,WAAW,EACX,WAAW,EACX,WAAW,EACZ,MAAM,SAAS,CAAC;AAKjB,qBACa,gBAAiB,YAAW,yBAAyB;IAG9D,OAAO,CAAC,QAAQ,CAAC,UAAU;IAE3B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAFZ,UAAU,EAAE,UAAU,EAEtB,YAAY,EAAE,WAAW;IAK5C,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI;IAczD,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI;IAiBzD,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI;CAiB1D"}
|
|
@@ -36,20 +36,38 @@ let ClientSubscriber = class ClientSubscriber {
|
|
|
36
36
|
};
|
|
37
37
|
this.rmsRMQClient.emit(mezgeb_enum_1.RecordInsertion, payload);
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
afterUpdate(event) {
|
|
40
|
+
var _a, _b, _c;
|
|
41
|
+
if (!event.databaseEntity || !event.entity)
|
|
42
42
|
return;
|
|
43
|
-
}
|
|
44
43
|
const ds = this.dataSource;
|
|
45
44
|
const payload = {
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
user: ds.user,
|
|
46
|
+
entityName: event.metadata.tableName,
|
|
47
|
+
entityId: (_b = (_a = event.entity) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : (_c = event.databaseEntity) === null || _c === void 0 ? void 0 : _c.id,
|
|
48
48
|
requestId: ds.requestId,
|
|
49
|
-
|
|
49
|
+
createdAt: new Date(),
|
|
50
|
+
before: event.databaseEntity,
|
|
51
|
+
after: event.entity,
|
|
52
|
+
};
|
|
53
|
+
this.rmsRMQClient.emit(mezgeb_enum_1.RecordUpdate, payload);
|
|
54
|
+
}
|
|
55
|
+
afterRemove(event) {
|
|
56
|
+
var _a;
|
|
57
|
+
const before = (_a = event.databaseEntity) !== null && _a !== void 0 ? _a : event.entity;
|
|
58
|
+
if (!before)
|
|
59
|
+
return;
|
|
60
|
+
const ds = this.dataSource;
|
|
61
|
+
const payload = {
|
|
50
62
|
user: ds.user,
|
|
63
|
+
entityName: event.metadata.tableName,
|
|
64
|
+
entityId: before === null || before === void 0 ? void 0 : before.id,
|
|
65
|
+
requestId: ds.requestId,
|
|
66
|
+
createdAt: new Date(),
|
|
67
|
+
before,
|
|
68
|
+
after: null,
|
|
51
69
|
};
|
|
52
|
-
this.rmsRMQClient.emit(
|
|
70
|
+
this.rmsRMQClient.emit(mezgeb_enum_1.RecordDeletion, payload);
|
|
53
71
|
}
|
|
54
72
|
};
|
|
55
73
|
exports.ClientSubscriber = ClientSubscriber;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AuditLogCommandService } from '../services/audit-log-command.service';
|
|
2
|
-
import {
|
|
2
|
+
import { ChangeEventDTO, CreateEventDTO } from '../../mezgeb.dto';
|
|
3
3
|
export declare class AuditLogCommandController {
|
|
4
4
|
private readonly auditLogService;
|
|
5
5
|
constructor(auditLogService: AuditLogCommandService);
|
|
6
6
|
handleAuditLog(data: CreateEventDTO): Promise<void>;
|
|
7
|
-
handleApproveTransaction(payload:
|
|
8
|
-
handleRollbackTransaction(payload:
|
|
7
|
+
handleApproveTransaction(payload: ChangeEventDTO): Promise<void>;
|
|
8
|
+
handleRollbackTransaction(payload: ChangeEventDTO): Promise<void>;
|
|
9
9
|
getAuditLogs(entityId: string, application: string, skip: number, take: number): Promise<[import("../entities/audit-log-command.entity").AuditLogCommand[], number]>;
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=audit-log-command.controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-log-command.controller.d.ts","sourceRoot":"","sources":["../../../../libs/mezgeb/src/mezgeb/listener/controllers/audit-log-command.controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAI/E,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"audit-log-command.controller.d.ts","sourceRoot":"","sources":["../../../../libs/mezgeb/src/mezgeb/listener/controllers/audit-log-command.controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAI/E,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElE,qBAGa,yBAAyB;IACxB,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAAf,eAAe,EAAE,sBAAsB;IAI9D,cAAc,CAAC,IAAI,EAAE,cAAc;IAMnC,wBAAwB,CAAC,OAAO,EAAE,cAAc;IAMhD,yBAAyB,CAAC,OAAO,EAAE,cAAc;IAiBjD,YAAY,CACG,QAAQ,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM;CAQ9B"}
|
|
@@ -66,14 +66,14 @@ __decorate([
|
|
|
66
66
|
(0, microservices_1.EventPattern)(mezgeb_enum_1.RecordUpdate),
|
|
67
67
|
(0, common_1.UseInterceptors)(event_nack_interceptor_1.EventAcknowledgmentInterceptor),
|
|
68
68
|
__metadata("design:type", Function),
|
|
69
|
-
__metadata("design:paramtypes", [mezgeb_dto_1.
|
|
69
|
+
__metadata("design:paramtypes", [mezgeb_dto_1.ChangeEventDTO]),
|
|
70
70
|
__metadata("design:returntype", Promise)
|
|
71
71
|
], AuditLogCommandController.prototype, "handleApproveTransaction", null);
|
|
72
72
|
__decorate([
|
|
73
73
|
(0, microservices_1.EventPattern)(mezgeb_enum_1.RecordDeletion),
|
|
74
74
|
(0, common_1.UseInterceptors)(event_nack_interceptor_1.EventAcknowledgmentInterceptor),
|
|
75
75
|
__metadata("design:type", Function),
|
|
76
|
-
__metadata("design:paramtypes", [mezgeb_dto_1.
|
|
76
|
+
__metadata("design:paramtypes", [mezgeb_dto_1.ChangeEventDTO]),
|
|
77
77
|
__metadata("design:returntype", Promise)
|
|
78
78
|
], AuditLogCommandController.prototype, "handleRollbackTransaction", null);
|
|
79
79
|
__decorate([
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Repository } from 'typeorm';
|
|
2
2
|
import { AuditLog } from '../entities/audit-log.entity';
|
|
3
3
|
import { AuditLogCommand } from '../entities/audit-log-command.entity';
|
|
4
|
-
import {
|
|
4
|
+
import { ChangeEventDTO, CreateEventDTO } from '../../mezgeb.dto';
|
|
5
5
|
export declare class AuditLogCommandService {
|
|
6
6
|
private auditLogRepository;
|
|
7
7
|
private auditLogCommandRepository;
|
|
8
8
|
constructor(auditLogRepository: Repository<AuditLog>, auditLogCommandRepository: Repository<AuditLogCommand>);
|
|
9
9
|
create(itemData: CreateEventDTO): Promise<void>;
|
|
10
|
-
update(itemData:
|
|
11
|
-
delete(itemData:
|
|
10
|
+
update(itemData: ChangeEventDTO): Promise<void>;
|
|
11
|
+
delete(itemData: ChangeEventDTO): Promise<void>;
|
|
12
12
|
auditParents(entity: any, method: 'INSERT_CHILD' | 'DELETE_CHILD', childEntityName: string, auditLogId: string): Promise<void>;
|
|
13
13
|
private changeCamelToSnakeCase;
|
|
14
14
|
pluralizeAndChangeCase(word: string): string;
|
|
@@ -16,8 +16,7 @@ export declare class AuditLogCommandService {
|
|
|
16
16
|
skip?: number;
|
|
17
17
|
take?: number;
|
|
18
18
|
}): Promise<[AuditLogCommand[], number]>;
|
|
19
|
-
private
|
|
20
|
-
private mapQueryToObject;
|
|
19
|
+
private getAuditItemById;
|
|
21
20
|
private parseInput;
|
|
22
21
|
}
|
|
23
22
|
//# sourceMappingURL=audit-log-command.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-log-command.service.d.ts","sourceRoot":"","sources":["../../../../libs/mezgeb/src/mezgeb/listener/services/audit-log-command.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAiB,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"audit-log-command.service.d.ts","sourceRoot":"","sources":["../../../../libs/mezgeb/src/mezgeb/listener/services/audit-log-command.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAiB,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEjF,qBACa,sBAAsB;IAG/B,OAAO,CAAC,kBAAkB;IAE1B,OAAO,CAAC,yBAAyB;gBAFzB,kBAAkB,EAAE,UAAU,CAAC,QAAQ,CAAC,EAExC,yBAAyB,EAAE,UAAU,CAAC,eAAe,CAAC;IAG1D,MAAM,CAAC,QAAQ,EAAE,cAAc;IAS/B,MAAM,CAAC,QAAQ,EAAE,cAAc;IA4D/B,MAAM,CAAC,QAAQ,EAAE,cAAc;IA2B/B,YAAY,CAChB,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,cAAc,GAAG,cAAc,EACvC,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,MAAM;IA0CpB,OAAO,CAAC,sBAAsB;IAI9B,sBAAsB,CAAC,IAAI,EAAE,MAAM;IAsB7B,YAAY,CAChB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,QAAQ,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO;YAwCnC,gBAAgB;IAgB9B,OAAO,CAAC,UAAU;CAWnB"}
|
|
@@ -40,40 +40,54 @@ let AuditLogCommandService = class AuditLogCommandService {
|
|
|
40
40
|
}
|
|
41
41
|
update(itemData) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
|
|
44
|
-
const
|
|
43
|
+
var _a, _b, _c, _d, _e;
|
|
44
|
+
const before = (_a = itemData.before) !== null && _a !== void 0 ? _a : {};
|
|
45
|
+
const after = (_b = itemData.after) !== null && _b !== void 0 ? _b : {};
|
|
46
|
+
const entityId = (_d = (_c = itemData.entityId) !== null && _c !== void 0 ? _c : before === null || before === void 0 ? void 0 : before.id) !== null && _d !== void 0 ? _d : after === null || after === void 0 ? void 0 : after.id;
|
|
47
|
+
if (!entityId || !itemData.entityName)
|
|
48
|
+
return;
|
|
49
|
+
const auditItem = yield this.getAuditItemById(itemData.entityName, entityId);
|
|
45
50
|
if (!auditItem)
|
|
46
51
|
return;
|
|
47
|
-
const entity = Object.assign(Object.assign({}, auditItem.entity), item.setParams);
|
|
48
52
|
const changes = [];
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
const keys = new Set([
|
|
54
|
+
...Object.keys(before || {}),
|
|
55
|
+
...Object.keys(after || {}),
|
|
56
|
+
]);
|
|
57
|
+
for (const key of keys) {
|
|
58
|
+
if (key === 'updatedAt')
|
|
51
59
|
continue;
|
|
52
|
-
|
|
60
|
+
const fromValue = before === null || before === void 0 ? void 0 : before[key];
|
|
61
|
+
const toValue = after === null || after === void 0 ? void 0 : after[key];
|
|
62
|
+
if (fromValue == toValue)
|
|
53
63
|
continue;
|
|
54
|
-
if (
|
|
64
|
+
if (fromValue == '' && toValue == undefined)
|
|
55
65
|
continue;
|
|
56
|
-
if (
|
|
66
|
+
if (fromValue == undefined && toValue == '')
|
|
57
67
|
continue;
|
|
58
68
|
changes.push({
|
|
59
69
|
field: key,
|
|
60
|
-
from: this.parseInput(
|
|
61
|
-
to: this.parseInput(
|
|
70
|
+
from: this.parseInput(fromValue),
|
|
71
|
+
to: this.parseInput(toValue),
|
|
62
72
|
});
|
|
63
73
|
}
|
|
64
74
|
if (changes.length === 0)
|
|
65
75
|
return;
|
|
66
|
-
const newAuditItem = this.auditLogCommandRepository.create(Object.assign(Object.assign({}, auditItem), { entity, auditLogId:
|
|
76
|
+
const newAuditItem = this.auditLogCommandRepository.create(Object.assign(Object.assign({}, auditItem), { entity: after, entityId, auditLogId: itemData.requestId, parentId: auditItem.id, id: undefined, createdAt: new Date((_e = itemData.createdAt) !== null && _e !== void 0 ? _e : new Date()), queryMethod: 'UPDATE', changes }));
|
|
67
77
|
yield this.auditLogCommandRepository.insert(newAuditItem);
|
|
68
78
|
});
|
|
69
79
|
}
|
|
70
80
|
delete(itemData) {
|
|
71
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
|
|
73
|
-
const
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
const before = (_a = itemData.before) !== null && _a !== void 0 ? _a : {};
|
|
84
|
+
const entityId = (_b = itemData.entityId) !== null && _b !== void 0 ? _b : before === null || before === void 0 ? void 0 : before.id;
|
|
85
|
+
if (!entityId || !itemData.entityName)
|
|
86
|
+
return;
|
|
87
|
+
const auditItem = yield this.getAuditItemById(itemData.entityName, entityId);
|
|
74
88
|
if (!auditItem)
|
|
75
89
|
return;
|
|
76
|
-
const newAuditItem = this.auditLogCommandRepository.create(Object.assign(Object.assign({}, auditItem), { entity:
|
|
90
|
+
const newAuditItem = this.auditLogCommandRepository.create(Object.assign(Object.assign({}, auditItem), { entity: before, entityId, auditLogId: itemData.requestId, parentId: auditItem.id, id: undefined, createdAt: new Date((_c = itemData.createdAt) !== null && _c !== void 0 ? _c : new Date()), queryMethod: 'DELETE' }));
|
|
77
91
|
yield this.auditLogCommandRepository.insert(newAuditItem);
|
|
78
92
|
});
|
|
79
93
|
}
|
|
@@ -161,9 +175,9 @@ let AuditLogCommandService = class AuditLogCommandService {
|
|
|
161
175
|
return yield dataQuery.getManyAndCount();
|
|
162
176
|
});
|
|
163
177
|
}
|
|
164
|
-
|
|
178
|
+
getAuditItemById(entityName, entityId) {
|
|
165
179
|
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
-
|
|
180
|
+
return yield this.auditLogCommandRepository
|
|
167
181
|
.createQueryBuilder('cmd')
|
|
168
182
|
.select([
|
|
169
183
|
'cmd.id',
|
|
@@ -172,57 +186,10 @@ let AuditLogCommandService = class AuditLogCommandService {
|
|
|
172
186
|
'cmd.entityName',
|
|
173
187
|
'cmd.createdAt',
|
|
174
188
|
])
|
|
175
|
-
.where('cmd.entityName = :entityName', { entityName
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
qb.orderBy('cmd.createdAt', 'DESC');
|
|
180
|
-
return yield qb.getOne();
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
mapQueryToObject(payload) {
|
|
184
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
var _a;
|
|
186
|
-
const { query, parameters, user, requestId, createdAt } = payload;
|
|
187
|
-
let setMatches = [];
|
|
188
|
-
if (query.startsWith('UPDATE')) {
|
|
189
|
-
const setClause = query.split('SET')[1].split('WHERE')[0].trim();
|
|
190
|
-
setMatches = setClause.match(/"[^"]+"\s*=\s*\$\d+/g) || [];
|
|
191
|
-
}
|
|
192
|
-
const whereClause = ((_a = query.split('WHERE')[1]) === null || _a === void 0 ? void 0 : _a.trim()) || '';
|
|
193
|
-
const whereMatches = whereClause.match(/"[^"]+"\s*(=|IN|BETWEEN|<|>|<=|>=|<>)\s*\(?\$?\d+(,\s*\$?\d+)*\)?/g) || [];
|
|
194
|
-
const allMatches = [...setMatches, ...whereMatches];
|
|
195
|
-
const setParams = {};
|
|
196
|
-
const whereParams = {};
|
|
197
|
-
allMatches.forEach((match, index) => {
|
|
198
|
-
const cleanedMatch = match.replace(/"/g, '').trim();
|
|
199
|
-
if (cleanedMatch.startsWith('(')) {
|
|
200
|
-
const paramKey = `param${index}`;
|
|
201
|
-
const paramList = cleanedMatch.match(/\$?\d+/g) || [];
|
|
202
|
-
whereParams[paramKey] = paramList.map((param) => parseInt(param.replace('$', ''), 10));
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
const [key, param] = cleanedMatch
|
|
206
|
-
.split(/=|IN|BETWEEN|<|>|<=|>=|<>/)
|
|
207
|
-
.map((str) => str.trim());
|
|
208
|
-
if (index < setMatches.length) {
|
|
209
|
-
setParams[key] = parameters[index];
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
whereParams[key] = parameters[index];
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
return {
|
|
217
|
-
setParams,
|
|
218
|
-
whereParams,
|
|
219
|
-
user,
|
|
220
|
-
requestId,
|
|
221
|
-
createdAt,
|
|
222
|
-
query,
|
|
223
|
-
entityName: query.split('"')[1],
|
|
224
|
-
entityId: whereParams['id'],
|
|
225
|
-
};
|
|
189
|
+
.where('cmd.entityName = :entityName', { entityName })
|
|
190
|
+
.andWhere('cmd.entityId = :entityId', { entityId })
|
|
191
|
+
.orderBy('cmd.createdAt', 'DESC')
|
|
192
|
+
.getOne();
|
|
226
193
|
});
|
|
227
194
|
}
|
|
228
195
|
parseInput(input) {
|
|
@@ -30,6 +30,15 @@ export declare class CreateEventDTO {
|
|
|
30
30
|
query?: string;
|
|
31
31
|
parameters?: any[];
|
|
32
32
|
}
|
|
33
|
+
export declare class ChangeEventDTO {
|
|
34
|
+
entityName: string;
|
|
35
|
+
entityId?: string;
|
|
36
|
+
user: any;
|
|
37
|
+
requestId: string;
|
|
38
|
+
createdAt?: Date;
|
|
39
|
+
before?: any;
|
|
40
|
+
after?: any;
|
|
41
|
+
}
|
|
33
42
|
export declare class EmitQueryDTO {
|
|
34
43
|
createdAt: Date;
|
|
35
44
|
query: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mezgeb.dto.d.ts","sourceRoot":"","sources":["../../libs/mezgeb/src/mezgeb/mezgeb.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AA2CvD,qBAAa,iBAAiB;IAC5B,aAAa,EAAG,sBAAsB,CAAC;IACvC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,WAAW,EAAG,MAAM,CAAC;IACrB,MAAM,EAAG,MAAM,CAAC;IAChB,WAAW,EAAG,GAAG,CAAC;IAClB,aAAa,EAAG,GAAG,CAAC;IACpB,UAAU,EAAG,MAAM,CAAC;IACpB,SAAS,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EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,EAAE,EAAE,MAAM,CAAC;KACZ,CAAC;CACH;AAED,qBAAa,yBAAyB;IACpC,SAAS,EAAG,MAAM,CAAC;IACnB,aAAa,EAAG,MAAM,CAAC;IACvB,UAAU,EAAG,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApproveTransactionPayload = exports.AuditChildDto = exports.EmitQueryDTO = exports.CreateEventDTO = exports.UpdateEventDTO = exports.CreateAuditLogDto = void 0;
|
|
3
|
+
exports.ApproveTransactionPayload = exports.AuditChildDto = exports.EmitQueryDTO = exports.ChangeEventDTO = exports.CreateEventDTO = exports.UpdateEventDTO = exports.CreateAuditLogDto = void 0;
|
|
4
4
|
// export class CreateAuditLogDto {
|
|
5
5
|
// requestMethod!: EAuditLogRequestMethod;
|
|
6
6
|
// id!: string;
|
|
@@ -48,6 +48,9 @@ exports.UpdateEventDTO = UpdateEventDTO;
|
|
|
48
48
|
class CreateEventDTO {
|
|
49
49
|
}
|
|
50
50
|
exports.CreateEventDTO = CreateEventDTO;
|
|
51
|
+
class ChangeEventDTO {
|
|
52
|
+
}
|
|
53
|
+
exports.ChangeEventDTO = ChangeEventDTO;
|
|
51
54
|
class EmitQueryDTO {
|
|
52
55
|
}
|
|
53
56
|
exports.EmitQueryDTO = EmitQueryDTO;
|