@nest-util/nest-crud 1.2.1 → 2.0.0
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/lib/controllers/nest-crud.controller.d.ts.map +1 -1
- package/dist/lib/controllers/nest-crud.controller.js +11 -10
- package/dist/lib/entities/approval-status.entity.js +3 -3
- package/dist/lib/entities/modification-request-history.entity.js +2 -2
- package/dist/lib/helpers/exception-filter.helper.d.ts.map +1 -1
- package/dist/lib/helpers/exception-filter.helper.js +3 -7
- package/dist/lib/interceptors/response.interceptor.d.ts +5 -1
- package/dist/lib/interceptors/response.interceptor.d.ts.map +1 -1
- package/dist/lib/interceptors/response.interceptor.js +21 -5
- package/dist/lib/services/nest-crud.service.d.ts.map +1 -1
- package/dist/lib/services/nest-crud.service.js +21 -22
- package/package.json +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nest-crud.controller.d.ts","sourceRoot":"","sources":["../../../src/lib/controllers/nest-crud.controller.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"nest-crud.controller.d.ts","sourceRoot":"","sources":["../../../src/lib/controllers/nest-crud.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,IAAI,EAEL,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,2CAA2C,CAAC;AAEn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G,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1D,WAAW,CAAC,CACV,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,aAAa,GACnB,OAAO,CAAC;QAAE,QAAQ,EAAE,kBAAkB,CAAC;QAAC,OAAO,EAAE,mBAAmB,EAAE,CAAA;KAAE,CAAC,CAAC;IAC7E,eAAe,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChF,cAAc,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/E,mBAAmB,CAAC,CAClB,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,0BAA0B,EAC/B,IAAI,CAAC,EAAE,aAAa,GACnB,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/B,gBAAgB,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAClF;AAyDD,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EACnD,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,EACnB,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,EACnB,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,EACrB,OAAO,CAAC,EAAE,4BAA4B,GACrC,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAiPnC"}
|
|
@@ -4,6 +4,7 @@ exports.AUTH_PERMISSIONS_METADATA_KEY = void 0;
|
|
|
4
4
|
exports.CreateNestedCrudController = CreateNestedCrudController;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
|
+
const nest_error_1 = require("@nest-util/nest-error");
|
|
7
8
|
const swagger_1 = require("@nestjs/swagger");
|
|
8
9
|
const response_message_decorator_1 = require("../decorators/response-message.decorator");
|
|
9
10
|
const audit_log_decorator_1 = require("../decorators/audit-log.decorator");
|
|
@@ -49,7 +50,7 @@ function CreateNestedCrudController(createDto, updateDto, responseDto, options)
|
|
|
49
50
|
}
|
|
50
51
|
ensureEndpointEnabled(endpoint) {
|
|
51
52
|
if (this.service.disabledEndpoints?.includes(endpoint)) {
|
|
52
|
-
throw
|
|
53
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
findAll(query) {
|
|
@@ -57,7 +58,7 @@ function CreateNestedCrudController(createDto, updateDto, responseDto, options)
|
|
|
57
58
|
// Cursor-based pagination: dispatch to cursor endpoint
|
|
58
59
|
if (query.cursor !== undefined) {
|
|
59
60
|
if (!this.service.findAllWithCursor) {
|
|
60
|
-
throw
|
|
61
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
61
62
|
}
|
|
62
63
|
return this.service.findAllWithCursor(query);
|
|
63
64
|
}
|
|
@@ -66,7 +67,7 @@ function CreateNestedCrudController(createDto, updateDto, responseDto, options)
|
|
|
66
67
|
findMine(user, query) {
|
|
67
68
|
this.ensureEndpointEnabled('findMine');
|
|
68
69
|
if (!this.service.findMine) {
|
|
69
|
-
throw
|
|
70
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
70
71
|
}
|
|
71
72
|
return this.service.findMine(user.id, query);
|
|
72
73
|
}
|
|
@@ -81,42 +82,42 @@ function CreateNestedCrudController(createDto, updateDto, responseDto, options)
|
|
|
81
82
|
changeStatus(id, dto, user) {
|
|
82
83
|
this.ensureEndpointEnabled('changeStatus');
|
|
83
84
|
if (!this.service.changeStatus) {
|
|
84
|
-
throw
|
|
85
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
85
86
|
}
|
|
86
87
|
return this.service.changeStatus(id, dto.status, user);
|
|
87
88
|
}
|
|
88
89
|
getApproval(id, user) {
|
|
89
90
|
this.ensureEndpointEnabled('getApproval');
|
|
90
91
|
if (!this.service.getApproval) {
|
|
91
|
-
throw
|
|
92
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
92
93
|
}
|
|
93
94
|
return this.service.getApproval(id, user);
|
|
94
95
|
}
|
|
95
96
|
approveApproval(id, user) {
|
|
96
97
|
this.ensureEndpointEnabled('approveApproval');
|
|
97
98
|
if (!this.service.approveApproval) {
|
|
98
|
-
throw
|
|
99
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
99
100
|
}
|
|
100
101
|
return this.service.approveApproval(id, user);
|
|
101
102
|
}
|
|
102
103
|
rejectApproval(id, user) {
|
|
103
104
|
this.ensureEndpointEnabled('rejectApproval');
|
|
104
105
|
if (!this.service.rejectApproval) {
|
|
105
|
-
throw
|
|
106
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
106
107
|
}
|
|
107
108
|
return this.service.rejectApproval(id, user);
|
|
108
109
|
}
|
|
109
110
|
requestModification(id, dto, user) {
|
|
110
111
|
this.ensureEndpointEnabled('requestModification');
|
|
111
112
|
if (!this.service.requestModification) {
|
|
112
|
-
throw
|
|
113
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
113
114
|
}
|
|
114
115
|
return this.service.requestModification(id, dto, user);
|
|
115
116
|
}
|
|
116
117
|
resubmitApproval(id, user) {
|
|
117
118
|
this.ensureEndpointEnabled('resubmitApproval');
|
|
118
119
|
if (!this.service.resubmitApproval) {
|
|
119
|
-
throw
|
|
120
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
120
121
|
}
|
|
121
122
|
return this.service.resubmitApproval(id, user);
|
|
122
123
|
}
|
|
@@ -127,7 +128,7 @@ function CreateNestedCrudController(createDto, updateDto, responseDto, options)
|
|
|
127
128
|
findAuditLogs(query) {
|
|
128
129
|
this.ensureEndpointEnabled('findAuditLogs');
|
|
129
130
|
if (!this.service.findAuditLogs) {
|
|
130
|
-
throw
|
|
131
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
131
132
|
}
|
|
132
133
|
return this.service.findAuditLogs(query);
|
|
133
134
|
}
|
|
@@ -32,7 +32,7 @@ tslib_1.__decorate([
|
|
|
32
32
|
], ApprovalStatusEntity.prototype, "status", void 0);
|
|
33
33
|
tslib_1.__decorate([
|
|
34
34
|
(0, typeorm_1.Index)(),
|
|
35
|
-
(0, typeorm_1.Column)({ nullable: true }),
|
|
35
|
+
(0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
|
|
36
36
|
tslib_1.__metadata("design:type", Object)
|
|
37
37
|
], ApprovalStatusEntity.prototype, "requestedBy", void 0);
|
|
38
38
|
tslib_1.__decorate([
|
|
@@ -44,7 +44,7 @@ tslib_1.__decorate([
|
|
|
44
44
|
tslib_1.__metadata("design:type", Object)
|
|
45
45
|
], ApprovalStatusEntity.prototype, "currentModifications", void 0);
|
|
46
46
|
tslib_1.__decorate([
|
|
47
|
-
(0, typeorm_1.Column)({ nullable: true }),
|
|
47
|
+
(0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
|
|
48
48
|
tslib_1.__metadata("design:type", Object)
|
|
49
49
|
], ApprovalStatusEntity.prototype, "decidedBy", void 0);
|
|
50
50
|
tslib_1.__decorate([
|
|
@@ -52,7 +52,7 @@ tslib_1.__decorate([
|
|
|
52
52
|
tslib_1.__metadata("design:type", Object)
|
|
53
53
|
], ApprovalStatusEntity.prototype, "decidedAt", void 0);
|
|
54
54
|
tslib_1.__decorate([
|
|
55
|
-
(0, typeorm_1.Column)({ nullable: true }),
|
|
55
|
+
(0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
|
|
56
56
|
tslib_1.__metadata("design:type", Object)
|
|
57
57
|
], ApprovalStatusEntity.prototype, "resubmittedBy", void 0);
|
|
58
58
|
tslib_1.__decorate([
|
|
@@ -32,11 +32,11 @@ tslib_1.__decorate([
|
|
|
32
32
|
], ModificationRequestHistoryEntity.prototype, "modifications", void 0);
|
|
33
33
|
tslib_1.__decorate([
|
|
34
34
|
(0, typeorm_1.Index)(),
|
|
35
|
-
(0, typeorm_1.Column)({ nullable: true }),
|
|
35
|
+
(0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
|
|
36
36
|
tslib_1.__metadata("design:type", Object)
|
|
37
37
|
], ModificationRequestHistoryEntity.prototype, "requestedBy", void 0);
|
|
38
38
|
tslib_1.__decorate([
|
|
39
|
-
(0, typeorm_1.Column)({ nullable: true }),
|
|
39
|
+
(0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
|
|
40
40
|
tslib_1.__metadata("design:type", Object)
|
|
41
41
|
], ModificationRequestHistoryEntity.prototype, "note", void 0);
|
|
42
42
|
tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception-filter.helper.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/exception-filter.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,eAAe,EAEhB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAU3C,qBACa,sBAAuB,YAAW,eAAe;IAC5D,KAAK,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"exception-filter.helper.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/exception-filter.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,eAAe,EAEhB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAU3C,qBACa,sBAAuB,YAAW,eAAe;IAC5D,KAAK,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI;CAwB9D"}
|
|
@@ -14,13 +14,9 @@ let TypeOrmExceptionFilter = class TypeOrmExceptionFilter {
|
|
|
14
14
|
let message = 'Internal server error';
|
|
15
15
|
if (isUniqueViolation) {
|
|
16
16
|
status = common_1.HttpStatus.UNPROCESSABLE_ENTITY;
|
|
17
|
-
message
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.replace('Key ', '')
|
|
21
|
-
.replace(/[()]/g, '')
|
|
22
|
-
.trim();
|
|
23
|
-
}
|
|
17
|
+
// Generic message only — the raw driverError.detail (column / constraint /
|
|
18
|
+
// values) is intentionally NOT leaked to the client.
|
|
19
|
+
message = 'A record with this value already exists';
|
|
24
20
|
}
|
|
25
21
|
response.status(status).json({
|
|
26
22
|
status: 'error',
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { Reflector } from '@nestjs/core';
|
|
4
|
+
import { I18nService, LangResolverService } from '@nest-util/nest-error';
|
|
4
5
|
export declare class ResponseInterceptor implements NestInterceptor {
|
|
5
6
|
private readonly reflector;
|
|
6
|
-
|
|
7
|
+
private readonly i18n?;
|
|
8
|
+
private readonly langResolver?;
|
|
9
|
+
constructor(reflector: Reflector, i18n?: I18nService | undefined, langResolver?: LangResolverService | undefined);
|
|
7
10
|
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
11
|
+
private localize;
|
|
8
12
|
}
|
|
9
13
|
//# sourceMappingURL=response.interceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.interceptor.d.ts","sourceRoot":"","sources":["../../../src/lib/interceptors/response.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,gBAAgB,EAChB,WAAW,
|
|
1
|
+
{"version":3,"file":"response.interceptor.d.ts","sourceRoot":"","sources":["../../../src/lib/interceptors/response.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,gBAAgB,EAChB,WAAW,EAEZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAOzC,OAAO,EACL,WAAW,EACX,mBAAmB,EAEpB,MAAM,uBAAuB,CAAC;AAE/B,qBACa,mBAAoB,YAAW,eAAe;IAEvD,OAAO,CAAC,QAAQ,CAAC,SAAS;IACd,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;gBAFzB,SAAS,EAAE,SAAS,EACR,IAAI,CAAC,EAAE,WAAW,YAAA,EAClB,YAAY,CAAC,EAAE,mBAAmB,YAAA;IAGjE,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;IA8B5E,OAAO,CAAC,QAAQ;CAwBjB"}
|
|
@@ -6,9 +6,12 @@ const common_1 = require("@nestjs/common");
|
|
|
6
6
|
const operators_1 = require("rxjs/operators");
|
|
7
7
|
const core_1 = require("@nestjs/core");
|
|
8
8
|
const response_message_decorator_1 = require("../decorators/response-message.decorator");
|
|
9
|
+
const nest_error_1 = require("@nest-util/nest-error");
|
|
9
10
|
let ResponseInterceptor = class ResponseInterceptor {
|
|
10
|
-
constructor(reflector) {
|
|
11
|
+
constructor(reflector, i18n, langResolver) {
|
|
11
12
|
this.reflector = reflector;
|
|
13
|
+
this.i18n = i18n;
|
|
14
|
+
this.langResolver = langResolver;
|
|
12
15
|
}
|
|
13
16
|
intercept(context, next) {
|
|
14
17
|
const handler = context.getHandler();
|
|
@@ -20,9 +23,7 @@ let ResponseInterceptor = class ResponseInterceptor {
|
|
|
20
23
|
const name = isList
|
|
21
24
|
? entityConfig?.plural ?? 'Resources'
|
|
22
25
|
: entityConfig?.singular ?? 'Resource';
|
|
23
|
-
const finalMessage = action
|
|
24
|
-
? `${name} ${action} successfully`
|
|
25
|
-
: 'Request successful';
|
|
26
|
+
const finalMessage = this.localize(name, action, context);
|
|
26
27
|
return {
|
|
27
28
|
message: finalMessage,
|
|
28
29
|
data: data?.data ?? data ?? null,
|
|
@@ -31,9 +32,24 @@ let ResponseInterceptor = class ResponseInterceptor {
|
|
|
31
32
|
};
|
|
32
33
|
}));
|
|
33
34
|
}
|
|
35
|
+
localize(name, action, context) {
|
|
36
|
+
if (!this.i18n || !this.langResolver) {
|
|
37
|
+
return action ? `${name} ${action} successfully` : 'Request successful';
|
|
38
|
+
}
|
|
39
|
+
const request = context.switchToHttp().getRequest();
|
|
40
|
+
const lang = this.langResolver.resolve(request ?? { headers: {} });
|
|
41
|
+
const localizedAction = action
|
|
42
|
+
? this.i18n.translate(action, {}, lang)
|
|
43
|
+
: this.i18n.translate(nest_error_1.ErrorKey.MSG_REQUEST_SUCCESS, {}, lang);
|
|
44
|
+
return this.i18n.translate(nest_error_1.ErrorKey.SUCCESS_FORMAT, { entity: name, action: localizedAction }, lang);
|
|
45
|
+
}
|
|
34
46
|
};
|
|
35
47
|
exports.ResponseInterceptor = ResponseInterceptor;
|
|
36
48
|
exports.ResponseInterceptor = ResponseInterceptor = tslib_1.__decorate([
|
|
37
49
|
(0, common_1.Injectable)(),
|
|
38
|
-
tslib_1.
|
|
50
|
+
tslib_1.__param(1, (0, common_1.Optional)()),
|
|
51
|
+
tslib_1.__param(2, (0, common_1.Optional)()),
|
|
52
|
+
tslib_1.__metadata("design:paramtypes", [core_1.Reflector,
|
|
53
|
+
nest_error_1.I18nService,
|
|
54
|
+
nest_error_1.LangResolverService])
|
|
39
55
|
], ResponseInterceptor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nest-crud.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/nest-crud.service.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"nest-crud.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/nest-crud.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAe,aAAa,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAkB,SAAS,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,EACL,oBAAoB,EAGpB,sBAAsB,EAEtB,WAAW,EACZ,MAAM,yCAAyC,CAAC;AASjD,OAAO,EAEL,sBAAsB,EAEtB,kBAAkB,EAClB,mBAAmB,EAEnB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|
const common_1 = require("@nestjs/common");
|
|
6
|
+
const nest_error_1 = require("@nest-util/nest-error");
|
|
6
7
|
const audit_log_entity_1 = require("../entities/audit-log.entity");
|
|
7
8
|
const filter_helper_1 = require("../helpers/filter.helper");
|
|
8
9
|
const pagination_helper_1 = require("../helpers/pagination.helper");
|
|
@@ -91,7 +92,7 @@ let NestCrudService = class NestCrudService {
|
|
|
91
92
|
id,
|
|
92
93
|
});
|
|
93
94
|
if (!entity) {
|
|
94
|
-
throw
|
|
95
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RELATION_NOT_FOUND, { property: String(relation.property) });
|
|
95
96
|
}
|
|
96
97
|
payload[String(relation.property)] = entity;
|
|
97
98
|
delete payload[idField];
|
|
@@ -238,7 +239,7 @@ let NestCrudService = class NestCrudService {
|
|
|
238
239
|
async findOwnedEntity(id, user) {
|
|
239
240
|
const userId = user?.id;
|
|
240
241
|
if (userId === undefined || userId === null) {
|
|
241
|
-
throw
|
|
242
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.FORBIDDEN, nest_error_1.ErrorKey.AUTH_UNAUTHORIZED);
|
|
242
243
|
}
|
|
243
244
|
const qb = this.repo.createQueryBuilder('e');
|
|
244
245
|
this.applyOwnershipCondition(qb, userId);
|
|
@@ -264,9 +265,7 @@ let NestCrudService = class NestCrudService {
|
|
|
264
265
|
}
|
|
265
266
|
if (this.statusCreateAllow.length > 0 &&
|
|
266
267
|
!this.statusCreateAllow.includes(requested)) {
|
|
267
|
-
throw
|
|
268
|
-
.map(String)
|
|
269
|
-
.join(', ') || 'none'}`);
|
|
268
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.BAD_REQUEST, nest_error_1.ErrorKey.CRUD_INVALID_STATUS, { requested: String(requested) });
|
|
270
269
|
}
|
|
271
270
|
}
|
|
272
271
|
validateStatusTransition(existing, payload, user) {
|
|
@@ -285,13 +284,13 @@ let NestCrudService = class NestCrudService {
|
|
|
285
284
|
}
|
|
286
285
|
const entry = this.statusTransitions.get(current);
|
|
287
286
|
if (!entry) {
|
|
288
|
-
throw
|
|
287
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.BAD_REQUEST, nest_error_1.ErrorKey.CRUD_STATUS_TRANSITION_INVALID, { from: String(current), to: String(requestedValue) });
|
|
289
288
|
}
|
|
290
289
|
if (!entry.to.has(requestedValue)) {
|
|
291
|
-
throw
|
|
290
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.BAD_REQUEST, nest_error_1.ErrorKey.CRUD_STATUS_TRANSITION_INVALID, { from: String(current), to: String(requestedValue) });
|
|
292
291
|
}
|
|
293
292
|
if (entry.permission && !this.canBypassOwnershipForTransition(user, entry.permission)) {
|
|
294
|
-
throw
|
|
293
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.FORBIDDEN, nest_error_1.ErrorKey.CRUD_STATUS_TRANSITION_FORBIDDEN, { permission: entry.permission });
|
|
295
294
|
}
|
|
296
295
|
return {
|
|
297
296
|
from: current,
|
|
@@ -336,7 +335,7 @@ let NestCrudService = class NestCrudService {
|
|
|
336
335
|
}
|
|
337
336
|
async findMine(userId, query) {
|
|
338
337
|
if (!this.userOwnershipField && !this.findMineQuery) {
|
|
339
|
-
throw
|
|
338
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.BAD_REQUEST, nest_error_1.ErrorKey.CRUD_FIND_MINE_NOT_CONFIGURED);
|
|
340
339
|
}
|
|
341
340
|
const qb = this.repo.createQueryBuilder('e');
|
|
342
341
|
this.applyOwnershipCondition(qb, userId);
|
|
@@ -423,7 +422,7 @@ let NestCrudService = class NestCrudService {
|
|
|
423
422
|
});
|
|
424
423
|
}
|
|
425
424
|
if (!entity) {
|
|
426
|
-
throw
|
|
425
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
427
426
|
}
|
|
428
427
|
const result = this.toResponseDto
|
|
429
428
|
? this.toResponseDto(entity)
|
|
@@ -436,7 +435,7 @@ let NestCrudService = class NestCrudService {
|
|
|
436
435
|
this.userOwnershipField &&
|
|
437
436
|
!this.canBypassOwnership(user)) {
|
|
438
437
|
if (!user || user.id === undefined || user.id === null) {
|
|
439
|
-
throw
|
|
438
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.FORBIDDEN, nest_error_1.ErrorKey.AUTH_UNAUTHORIZED);
|
|
440
439
|
}
|
|
441
440
|
const field = String(this.userOwnershipField);
|
|
442
441
|
const matchingRelation = this.relations.find((r) => String(r.property) === field);
|
|
@@ -448,7 +447,7 @@ let NestCrudService = class NestCrudService {
|
|
|
448
447
|
if (payloadValue !== undefined && payloadValue !== null) {
|
|
449
448
|
// Value present — must match the authenticated user
|
|
450
449
|
if (String(payloadValue) !== String(user.id)) {
|
|
451
|
-
throw
|
|
450
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
452
451
|
}
|
|
453
452
|
}
|
|
454
453
|
else {
|
|
@@ -477,18 +476,18 @@ let NestCrudService = class NestCrudService {
|
|
|
477
476
|
}
|
|
478
477
|
async changeStatus(id, status, user) {
|
|
479
478
|
if (!this.isStatusPipelineConfigured()) {
|
|
480
|
-
throw
|
|
479
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_STATUS_NOT_CONFIGURED);
|
|
481
480
|
}
|
|
482
481
|
const payload = { [String(this.statusField)]: status };
|
|
483
482
|
return this.applyUpdateCore(id, payload, user);
|
|
484
483
|
}
|
|
485
484
|
async getApproval(id, user) {
|
|
486
485
|
if (!this.isApprovalPipelineConfigured()) {
|
|
487
|
-
throw
|
|
486
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_APPROVAL_NOT_CONFIGURED);
|
|
488
487
|
}
|
|
489
488
|
const approval = await this.loadApprovalStatus(id, user);
|
|
490
489
|
if (!approval) {
|
|
491
|
-
throw
|
|
490
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
492
491
|
}
|
|
493
492
|
const history = await this.getHistoryRepository().find({
|
|
494
493
|
where: { approvalStatusId: approval.id },
|
|
@@ -562,15 +561,15 @@ let NestCrudService = class NestCrudService {
|
|
|
562
561
|
}
|
|
563
562
|
async transitionApproval(id, action, user, modifications, note) {
|
|
564
563
|
if (!this.isApprovalPipelineConfigured()) {
|
|
565
|
-
throw
|
|
564
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_APPROVAL_NOT_CONFIGURED);
|
|
566
565
|
}
|
|
567
566
|
const permission = this.approvalPipeline?.permissions?.[action];
|
|
568
567
|
if (permission && !this.userHasPermission(user, permission)) {
|
|
569
|
-
throw
|
|
568
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.FORBIDDEN, nest_error_1.ErrorKey.CRUD_APPROVAL_FORBIDDEN, { permission, action });
|
|
570
569
|
}
|
|
571
570
|
const approval = await this.loadApprovalStatus(id, user);
|
|
572
571
|
if (!approval) {
|
|
573
|
-
throw
|
|
572
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
574
573
|
}
|
|
575
574
|
const current = approval.status;
|
|
576
575
|
const now = new Date();
|
|
@@ -607,7 +606,7 @@ let NestCrudService = class NestCrudService {
|
|
|
607
606
|
break;
|
|
608
607
|
case 'resubmit':
|
|
609
608
|
if (current !== approval_pipeline_interface_1.APPROVAL_STATUS.modificationRequested) {
|
|
610
|
-
throw
|
|
609
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.BAD_REQUEST, nest_error_1.ErrorKey.CRUD_APPROVAL_INVALID_TRANSITION, { action: 'resubmit', current: String(current) });
|
|
611
610
|
}
|
|
612
611
|
approval.status = approval_pipeline_interface_1.APPROVAL_STATUS.resubmitted;
|
|
613
612
|
approval.currentModifications = null;
|
|
@@ -620,7 +619,7 @@ let NestCrudService = class NestCrudService {
|
|
|
620
619
|
}
|
|
621
620
|
assertTransitionAllowed(action, current, allowedFrom) {
|
|
622
621
|
if (!allowedFrom.includes(current)) {
|
|
623
|
-
throw
|
|
622
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.BAD_REQUEST, nest_error_1.ErrorKey.CRUD_APPROVAL_INVALID_TRANSITION, { action, current: String(current) });
|
|
624
623
|
}
|
|
625
624
|
}
|
|
626
625
|
userHasPermission(user, permission) {
|
|
@@ -689,7 +688,7 @@ let NestCrudService = class NestCrudService {
|
|
|
689
688
|
});
|
|
690
689
|
}
|
|
691
690
|
if (!existing) {
|
|
692
|
-
throw
|
|
691
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
693
692
|
}
|
|
694
693
|
await this.executeHook(this.hooks.beforeUpdate, { payload, entity: existing, id });
|
|
695
694
|
const transition = this.validateStatusTransition(existing, payload, user);
|
|
@@ -715,7 +714,7 @@ let NestCrudService = class NestCrudService {
|
|
|
715
714
|
});
|
|
716
715
|
}
|
|
717
716
|
if (!existing) {
|
|
718
|
-
throw
|
|
717
|
+
throw (0, nest_error_1.keyed)(common_1.HttpStatus.NOT_FOUND, nest_error_1.ErrorKey.CRUD_RESOURCE_NOT_FOUND);
|
|
719
718
|
}
|
|
720
719
|
await this.executeHook(this.hooks.beforeRemove, { entity: existing, id });
|
|
721
720
|
const result = await this.repo.delete(id);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-util/nest-crud",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -28,10 +28,12 @@
|
|
|
28
28
|
"tslib": "^2.8.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@nest-util/nest-auth": "workspace:*"
|
|
31
|
+
"@nest-util/nest-auth": "workspace:*",
|
|
32
|
+
"@nest-util/nest-error": "workspace:*"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
35
|
"@nest-util/nest-auth": "workspace:*",
|
|
36
|
+
"@nest-util/nest-error": "workspace:*",
|
|
35
37
|
"@nestjs/common": "^11.0.0",
|
|
36
38
|
"@nestjs/core": "^11.0.0",
|
|
37
39
|
"@nestjs/event-emitter": "^3.0.0",
|