@steroidsjs/nest 1.0.1 → 1.0.2
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/README.md +8 -1
- package/infrastructure/filters/ValidationExceptionFilter.d.ts +5 -0
- package/infrastructure/filters/ValidationExceptionFilter.js +40 -0
- package/infrastructure/filters/ValidationExceptionFilter.js.map +1 -0
- package/package.json +4 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/usecases/exceptions/ValidationException.d.ts +6 -0
- package/usecases/exceptions/ValidationException.js +10 -0
- package/usecases/exceptions/ValidationException.js.map +1 -0
- package/usecases/helpers/ValidationHelper.d.ts +2 -0
- package/usecases/helpers/ValidationHelper.js +13 -0
- package/usecases/helpers/ValidationHelper.js.map +1 -0
- package/usecases/interfaces/IFormError.d.ts +3 -0
- package/usecases/interfaces/IFormError.js +3 -0
- package/usecases/interfaces/IFormError.js.map +1 -0
- package/usecases/services/CrudService.js +8 -2
- package/usecases/services/CrudService.js.map +1 -1
- package/infrastructure/exception/ValidationException.d.ts +0 -5
- package/infrastructure/exception/ValidationException.js +0 -12
- package/infrastructure/exception/ValidationException.js.map +0 -1
- package/infrastructure/pipes/ValidationPipe.d.ts +0 -4
- package/infrastructure/pipes/ValidationPipe.js +0 -37
- package/infrastructure/pipes/ValidationPipe.js.map +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationException = void 0;
|
|
4
|
+
class ValidationException {
|
|
5
|
+
constructor(errors) {
|
|
6
|
+
this.errors = errors;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.ValidationException = ValidationException;
|
|
10
|
+
//# sourceMappingURL=ValidationException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationException.js","sourceRoot":"","sources":["../../../src/usecases/exceptions/ValidationException.ts"],"names":[],"mappings":";;;AAGA,MAAa,mBAAmB;IAG5B,YAAY,MAAsC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAND,kDAMC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateOrReject = void 0;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const ValidationException_1 = require("../exceptions/ValidationException");
|
|
6
|
+
async function validateOrReject(model, validatorOptions) {
|
|
7
|
+
const errors = await (0, class_validator_1.validate)(model, validatorOptions);
|
|
8
|
+
if (errors.length) {
|
|
9
|
+
throw new ValidationException_1.ValidationException(errors);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.validateOrReject = validateOrReject;
|
|
13
|
+
//# sourceMappingURL=ValidationHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationHelper.js","sourceRoot":"","sources":["../../../src/usecases/helpers/ValidationHelper.ts"],"names":[],"mappings":";;;AAAA,qDAA2D;AAC3D,2EAAsE;AAE/D,KAAK,UAAU,gBAAgB,CAAC,KAAU,EAAE,gBAAmC;IAClF,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAQ,EAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACvD,IAAI,MAAM,CAAC,MAAM,EAAE;QACf,MAAM,IAAI,yCAAmB,CAAC,MAAM,CAAC,CAAC;KACzC;AACL,CAAC;AALD,4CAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFormError.js","sourceRoot":"","sources":["../../../src/usecases/interfaces/IFormError.ts"],"names":[],"mappings":""}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CrudService = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const DataMapperHelper_1 = require("../helpers/DataMapperHelper");
|
|
6
|
+
const ValidationHelper_1 = require("../helpers/ValidationHelper");
|
|
6
7
|
class CrudService {
|
|
7
8
|
constructor() {
|
|
8
9
|
this.primaryKey = 'id';
|
|
@@ -16,6 +17,7 @@ class CrudService {
|
|
|
16
17
|
return new ModelClass();
|
|
17
18
|
}
|
|
18
19
|
async search(dto) {
|
|
20
|
+
await (0, ValidationHelper_1.validateOrReject)(dto);
|
|
19
21
|
const repositoryResult = await this.repository.search(dto);
|
|
20
22
|
return repositoryResult;
|
|
21
23
|
}
|
|
@@ -24,12 +26,16 @@ class CrudService {
|
|
|
24
26
|
return model;
|
|
25
27
|
}
|
|
26
28
|
async create(dto) {
|
|
29
|
+
await (0, ValidationHelper_1.validateOrReject)(dto);
|
|
27
30
|
let model = this.dtoToModel(dto, this.createModel());
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
await (0, ValidationHelper_1.validateOrReject)(model);
|
|
32
|
+
const tmodel = await this.repository.create(model);
|
|
33
|
+
return tmodel;
|
|
30
34
|
}
|
|
31
35
|
async update(id, dto) {
|
|
36
|
+
await (0, ValidationHelper_1.validateOrReject)(dto);
|
|
32
37
|
let model = this.dtoToModel(dto, this.createModel());
|
|
38
|
+
await (0, ValidationHelper_1.validateOrReject)(model);
|
|
33
39
|
model = await this.repository.update((0, lodash_1.toInteger)(id), model);
|
|
34
40
|
return model;
|
|
35
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudService.js","sourceRoot":"","sources":["../../../src/usecases/services/CrudService.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;AAE/C,kEAA6D;
|
|
1
|
+
{"version":3,"file":"CrudService.js","sourceRoot":"","sources":["../../../src/usecases/services/CrudService.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;AAE/C,kEAA6D;AAG7D,kEAA6D;AAK7D,MAAa,WAAW;IAAxB;QAQc,eAAU,GAAW,IAAI,CAAC;IAuFxC,CAAC;IAxEG,IAAI,CAAC,UAAmC,EAAE,U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CAAgB,EAAC,KAAK,CAAC,CAAC;QAC9B,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAA,kBAAU,EAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;QAC5D,OAAO,KAAK,CAAC;IACjB,CAAC;IAMD,KAAK,CAAC,MAAM,CAAC,EAAmB;QAC5B,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAA,kBAAU,EAAC,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC;IAQS,UAAU,CAAC,GAAa,EAAE,KAAa;QAC7C,mCAAgB,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACzC,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA/FD,kCA+FC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationException = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
class ValidationException extends common_1.HttpException {
|
|
6
|
-
constructor(response) {
|
|
7
|
-
super(response, common_1.HttpStatus.BAD_REQUEST);
|
|
8
|
-
this.messages = response;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.ValidationException = ValidationException;
|
|
12
|
-
//# sourceMappingURL=ValidationException.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationException.js","sourceRoot":"","sources":["../../../src/infrastructure/exception/ValidationException.ts"],"names":[],"mappings":";;;AAAA,2CAAyD;AAEzD,MAAa,mBAAoB,SAAQ,sBAAa;IAGlD,YAAY,QAAQ;QAChB,KAAK,CAAC,QAAQ,EAAE,mBAAU,CAAC,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAPD,kDAOC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.ValidationPipe = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const class_transformer_1 = require("class-transformer");
|
|
12
|
-
const class_validator_1 = require("class-validator");
|
|
13
|
-
const ValidationException_1 = require("../exception/ValidationException");
|
|
14
|
-
let ValidationPipe = class ValidationPipe {
|
|
15
|
-
async transform(value, metadata) {
|
|
16
|
-
const obj = (0, class_transformer_1.plainToInstance)(metadata.metatype, value) || {};
|
|
17
|
-
if (typeof obj === 'object') {
|
|
18
|
-
const errors = await (0, class_validator_1.validate)(obj);
|
|
19
|
-
if (errors.length) {
|
|
20
|
-
throw new ValidationException_1.ValidationException({
|
|
21
|
-
errors: errors.reduce((result, item) => {
|
|
22
|
-
result[item.property] = []
|
|
23
|
-
.concat(obj[item.property] || [])
|
|
24
|
-
.concat(Object.values(item.constraints));
|
|
25
|
-
return result;
|
|
26
|
-
}, {}),
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
ValidationPipe = __decorate([
|
|
34
|
-
(0, common_1.Injectable)()
|
|
35
|
-
], ValidationPipe);
|
|
36
|
-
exports.ValidationPipe = ValidationPipe;
|
|
37
|
-
//# sourceMappingURL=ValidationPipe.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationPipe.js","sourceRoot":"","sources":["../../../src/infrastructure/pipes/ValidationPipe.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2E;AAC3E,yDAAkD;AAClD,qDAAyC;AACzC,0EAAqE;AAGrE,IAAa,cAAc,GAA3B,MAAa,cAAc;IACvB,KAAK,CAAC,SAAS,CAAC,KAAU,EAAE,QAA0B;QAClD,MAAM,GAAG,GAAG,IAAA,mCAAe,EAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QAC5D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YACzB,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAQ,EAAC,GAAG,CAAC,CAAC;YACnC,IAAI,MAAM,CAAC,MAAM,EAAE;gBACf,MAAM,IAAI,yCAAmB,CAAC;oBAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,CACjB,CAAC,MAAW,EAAE,IAAI,EAAE,EAAE;wBAClB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;6BACrB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;6BAChC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;wBAC7C,OAAO,MAAM,CAAC;oBAClB,CAAC,EACD,EAAE,CACL;iBACJ,CAAC,CAAC;aACN;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ,CAAA;AArBY,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CAqB1B;AArBY,wCAAc"}
|