@estgbue/mezgeb 0.0.48 → 0.0.50

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.
@@ -6,6 +6,13 @@ export declare class AuditLogCommandController {
6
6
  handleAuditLog(data: CreateEventDTO): Promise<void>;
7
7
  handleApproveTransaction(payload: ChangeEventDTO): Promise<void>;
8
8
  handleRollbackTransaction(payload: ChangeEventDTO): Promise<void>;
9
- getAuditLogs(entityId: string, application: string, skip: number, take: number): Promise<[import("../entities/audit-log-command.entity").AuditLogCommand[], number]>;
9
+ getAuditLogs(entityId: string, application: string, skip: number, take: number): Promise<{
10
+ count: number;
11
+ items: import("../entities/audit-log-command.entity").AuditLogCommand[];
12
+ }>;
13
+ getAllAuditLogs(application: string, skip: number, take: number): Promise<{
14
+ count: number;
15
+ items: import("../entities/audit-log-command.entity").AuditLogCommand[];
16
+ }>;
10
17
  }
11
18
  //# 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,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"}
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;;;;IAsBvB,eAAe,CACG,WAAW,EAAE,MAAM,EAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM;;;;CAO9B"}
@@ -53,6 +53,11 @@ let AuditLogCommandController = class AuditLogCommandController {
53
53
  return yield this.auditLogService.getAuditLogs(entityId, application, { skip, take });
54
54
  });
55
55
  }
56
+ getAllAuditLogs(application, skip, take) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ return yield this.auditLogService.getAllAuditLogs(application, { skip, take });
59
+ });
60
+ }
56
61
  };
57
62
  exports.AuditLogCommandController = AuditLogCommandController;
58
63
  __decorate([
@@ -98,6 +103,27 @@ __decorate([
98
103
  __metadata("design:paramtypes", [String, String, Number, Number]),
99
104
  __metadata("design:returntype", Promise)
100
105
  ], AuditLogCommandController.prototype, "getAuditLogs", null);
106
+ __decorate([
107
+ (0, common_1.Get)('all/:application'),
108
+ (0, swagger_1.ApiQuery)({
109
+ name: 'skip',
110
+ type: Number,
111
+ description: 'Number of records to skip for pagination. Optional',
112
+ required: false,
113
+ }),
114
+ (0, swagger_1.ApiQuery)({
115
+ name: 'take',
116
+ type: Number,
117
+ description: 'Number of records to take for pagination. Optional',
118
+ required: false,
119
+ }),
120
+ __param(0, (0, common_1.Param)('application')),
121
+ __param(1, (0, common_1.Query)('skip')),
122
+ __param(2, (0, common_1.Query)('take')),
123
+ __metadata("design:type", Function),
124
+ __metadata("design:paramtypes", [String, Number, Number]),
125
+ __metadata("design:returntype", Promise)
126
+ ], AuditLogCommandController.prototype, "getAllAuditLogs", null);
101
127
  exports.AuditLogCommandController = AuditLogCommandController = __decorate([
102
128
  (0, common_1.Controller)('audit-log-commands'),
103
129
  (0, swagger_1.ApiTags)('Audit Log'),
@@ -12,10 +12,21 @@ export declare class AuditLogCommandService {
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;
15
+ private buildAuditLogQuery;
16
+ getAllAuditLogs(application: string, paginate?: {
17
+ skip?: number;
18
+ take?: number;
19
+ }): Promise<{
20
+ count: number;
21
+ items: AuditLogCommand[];
22
+ }>;
15
23
  getAuditLogs(entityId: string, application: string, paginate?: {
16
24
  skip?: number;
17
25
  take?: number;
18
- }): Promise<[AuditLogCommand[], number]>;
26
+ }): Promise<{
27
+ count: number;
28
+ items: AuditLogCommand[];
29
+ }>;
19
30
  private getAuditItemById;
20
31
  private parseInput;
21
32
  }
@@ -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,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;IAU/B,MAAM,CAAC,QAAQ,EAAE,cAAc;IA+D/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"}
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;IAgB/B,MAAM,CAAC,QAAQ,EAAE,cAAc;IA+D/B,MAAM,CAAC,QAAQ,EAAE,cAAc;IAiC/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;IAsBnC,OAAO,CAAC,kBAAkB;IA0CpB,eAAe,CACnB,WAAW,EAAE,MAAM,EACnB,QAAQ,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO;;;;IAO3C,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;;;;YAOnC,gBAAgB;IAgB9B,OAAO,CAAC,UAAU;CAWnB"}
@@ -37,6 +37,7 @@ let AuditLogCommandService = class AuditLogCommandService {
37
37
  const auditItem = this.auditLogCommandRepository.create(Object.assign(Object.assign({}, itemData), { auditLogId: itemData.requestId, queryMethod: 'INSERT' }));
38
38
  common_1.Logger.log(`Creating insert audit log command for ${itemData.entityName} with ID ${itemData.entityId}`);
39
39
  yield this.auditLogCommandRepository.insert(auditItem);
40
+ yield this.auditParents(itemData.entity, 'INSERT_CHILD', itemData.entityName, itemData.requestId);
40
41
  });
41
42
  }
42
43
  update(itemData) {
@@ -94,6 +95,7 @@ let AuditLogCommandService = class AuditLogCommandService {
94
95
  return;
95
96
  const newAuditItem = this.auditLogCommandRepository.create(Object.assign(Object.assign({}, auditItem), { entity: before, entityId, auditLogId: itemData.requestId, parentId: auditItem.id, id: undefined, createdAt: new Date(), queryMethod: 'DELETE' }));
96
97
  yield this.auditLogCommandRepository.insert(newAuditItem);
98
+ yield this.auditParents(auditItem.entity, 'DELETE_CHILD', itemData.entityName, itemData.requestId);
97
99
  });
98
100
  }
99
101
  auditParents(entity, method, childEntityName, auditLogId) {
@@ -149,35 +151,45 @@ let AuditLogCommandService = class AuditLogCommandService {
149
151
  }
150
152
  return word + 's';
151
153
  }
154
+ buildAuditLogQuery(application, entityId, paginate = {}) {
155
+ var _a, _b;
156
+ const dataQuery = this.auditLogCommandRepository.createQueryBuilder('audit_log_commands');
157
+ dataQuery
158
+ .leftJoinAndSelect('audit_log_commands.auditLog', 'auditLog')
159
+ .andWhere('(audit_log_commands.auditLogId IS NULL OR auditLog.application = :application)', { application })
160
+ .andWhere('(audit_log_commands.auditLogId IS NULL OR auditLog.status = :status)', { status: 'Commit' })
161
+ .select([
162
+ 'audit_log_commands.id',
163
+ 'audit_log_commands.createdAt',
164
+ 'audit_log_commands.deletedAt',
165
+ 'audit_log_commands.entityName',
166
+ 'audit_log_commands.queryMethod',
167
+ 'audit_log_commands.changes',
168
+ 'audit_log_commands.payload',
169
+ 'auditLog.id',
170
+ 'auditLog.user',
171
+ ])
172
+ .addOrderBy('audit_log_commands.createdAt', 'DESC');
173
+ if (entityId) {
174
+ dataQuery.andWhere('audit_log_commands.entityId = :entityId', { entityId });
175
+ }
176
+ if (paginate) {
177
+ dataQuery.skip((_a = paginate.skip) !== null && _a !== void 0 ? _a : 0).take((_b = paginate.take) !== null && _b !== void 0 ? _b : 10);
178
+ }
179
+ return dataQuery;
180
+ }
181
+ getAllAuditLogs(application_1) {
182
+ return __awaiter(this, arguments, void 0, function* (application, paginate = {}) {
183
+ const dataQuery = this.buildAuditLogQuery(application, undefined, paginate);
184
+ const [items, count] = yield dataQuery.getManyAndCount();
185
+ return { count, items };
186
+ });
187
+ }
152
188
  getAuditLogs(entityId_1, application_1) {
153
189
  return __awaiter(this, arguments, void 0, function* (entityId, application, paginate = {}) {
154
- var _a, _b;
155
- const dataQuery = this.auditLogCommandRepository.createQueryBuilder('audit_log_commands');
156
- dataQuery
157
- .leftJoinAndSelect('audit_log_commands.auditLog', 'auditLog')
158
- .andWhere('(audit_log_commands.auditLogId IS NULL OR auditLog.application = :application)', { application })
159
- // .andWhere(
160
- // `(audit_log_commands.auditLogId IS NULL OR ("auditLog"."user"->>'organizationId')::uuid = :organizationId)`,
161
- // { organizationId: user.organization.id },
162
- // )
163
- .andWhere('(audit_log_commands.auditLogId IS NULL OR auditLog.status = :status)', { status: 'Commit' })
164
- .andWhere('audit_log_commands.entityId = :entityId', { entityId })
165
- .select([
166
- 'audit_log_commands.id',
167
- 'audit_log_commands.createdAt',
168
- 'audit_log_commands.deletedAt',
169
- 'audit_log_commands.entityName',
170
- 'audit_log_commands.queryMethod',
171
- 'audit_log_commands.changes',
172
- 'audit_log_commands.payload',
173
- 'auditLog.id',
174
- 'auditLog.user',
175
- ])
176
- .addOrderBy('audit_log_commands.createdAt', 'DESC');
177
- if (paginate) {
178
- dataQuery.skip((_a = paginate.skip) !== null && _a !== void 0 ? _a : 0).take((_b = paginate.take) !== null && _b !== void 0 ? _b : 10);
179
- }
180
- return yield dataQuery.getManyAndCount();
190
+ const dataQuery = this.buildAuditLogQuery(application, entityId, paginate);
191
+ const [items, count] = yield dataQuery.getManyAndCount();
192
+ return { count, items };
181
193
  });
182
194
  }
183
195
  getAuditItemById(entityName, entityId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estgbue/mezgeb",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "main": "./src/index",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"