@lenne.tech/nest-server 10.8.8 → 10.8.10
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/core/common/decorators/common-error.decorator.d.ts +27 -0
- package/dist/core/common/decorators/common-error.decorator.js +23 -2
- package/dist/core/common/decorators/common-error.decorator.js.map +1 -1
- package/dist/core/common/pipes/map-and-validate.pipe.js +5 -1
- package/dist/core/common/pipes/map-and-validate.pipe.js.map +1 -1
- package/dist/test/test.helper.js +14 -3
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/common/decorators/common-error.decorator.ts +23 -1
- package/src/core/common/pipes/map-and-validate.pipe.ts +5 -1
- package/src/test/test.helper.ts +18 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "10.8.
|
|
3
|
+
"version": "10.8.10",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -19,10 +19,32 @@ export const commonErrorSchema = {
|
|
|
19
19
|
type: 'object',
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
export const badRequestSchema = {
|
|
23
|
+
properties: {
|
|
24
|
+
message: { type: 'string' },
|
|
25
|
+
name: { type: 'string' },
|
|
26
|
+
options: {
|
|
27
|
+
additionalProperties: true,
|
|
28
|
+
type: 'object',
|
|
29
|
+
},
|
|
30
|
+
response: {
|
|
31
|
+
additionalProperties: {
|
|
32
|
+
additionalProperties: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
},
|
|
35
|
+
type: 'object',
|
|
36
|
+
},
|
|
37
|
+
type: 'object',
|
|
38
|
+
},
|
|
39
|
+
status: { type: 'number' },
|
|
40
|
+
},
|
|
41
|
+
type: 'object',
|
|
42
|
+
};
|
|
43
|
+
|
|
22
44
|
export function ApiCommonErrorResponses() {
|
|
23
45
|
return applyDecorators(
|
|
24
46
|
ApiUnauthorizedResponse({ schema: commonErrorSchema }),
|
|
25
47
|
ApiNotFoundResponse({ schema: commonErrorSchema }),
|
|
26
|
-
ApiBadRequestResponse({ schema:
|
|
48
|
+
ApiBadRequestResponse({ schema: badRequestSchema }),
|
|
27
49
|
);
|
|
28
50
|
}
|
|
@@ -25,7 +25,11 @@ export class MapAndValidatePipe implements PipeTransform {
|
|
|
25
25
|
// Validate
|
|
26
26
|
const errors = await validate(value, { forbidUnknownValues: false });
|
|
27
27
|
if (errors.length > 0) {
|
|
28
|
-
|
|
28
|
+
const result = {};
|
|
29
|
+
errors.forEach((e) => {
|
|
30
|
+
result[e.property] = e.constraints;
|
|
31
|
+
});
|
|
32
|
+
throw new BadRequestException(result);
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
return value;
|
package/src/test/test.helper.ts
CHANGED
|
@@ -303,12 +303,27 @@ export class TestHelper {
|
|
|
303
303
|
if (config.convertEnums) {
|
|
304
304
|
if (Array.isArray(config.convertEnums)) {
|
|
305
305
|
for (const key of Object.values(config.convertEnums)) {
|
|
306
|
-
const regExpStr = `(
|
|
306
|
+
const regExpStr = `(?<=${key}:\\s*)"([A-Z0-9_]+)"(?=\\s*[,\\]}])`;
|
|
307
307
|
const regExp = new RegExp(regExpStr, 'g');
|
|
308
|
-
query = query.replace(regExp,
|
|
308
|
+
query = query.replace(regExp, (match, group1) => {
|
|
309
|
+
// If group1 consists exclusively of digits, return original string
|
|
310
|
+
if (/^\d+$/.test(group1)) {
|
|
311
|
+
return match;
|
|
312
|
+
}
|
|
313
|
+
// Otherwise remove quotation marks
|
|
314
|
+
return group1;
|
|
315
|
+
});
|
|
309
316
|
}
|
|
310
317
|
} else {
|
|
311
|
-
|
|
318
|
+
const before = query.replace(/([_A-Za-z][_0-9A-Za-z]*:\s)\"([_A-Z][_0-9A-Z]*)\"/g, '$1$2');
|
|
319
|
+
query = query.replace(/(?<=[:\[,]\s*)"([A-Z0-9_]+)"(?=\s*[,\]\}])/g, (match, group1) => {
|
|
320
|
+
// If group1 only contains digits, the original string is returned
|
|
321
|
+
if (/^\d+$/.test(group1)) {
|
|
322
|
+
return match;
|
|
323
|
+
}
|
|
324
|
+
// Otherwise the quotation marks are removed
|
|
325
|
+
return group1;
|
|
326
|
+
});
|
|
312
327
|
}
|
|
313
328
|
}
|
|
314
329
|
|