@lenne.tech/nest-server 8.0.2 → 8.1.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/core/common/args/pagination.args.js +1 -1
- package/dist/core/common/args/pagination.args.js.map +1 -1
- package/dist/core/common/helpers/config.helper.d.ts +2 -1
- package/dist/core/common/helpers/config.helper.js +11 -7
- package/dist/core/common/helpers/config.helper.js.map +1 -1
- package/dist/core/common/helpers/context.helper.d.ts +7 -1
- package/dist/core/common/helpers/context.helper.js +33 -29
- package/dist/core/common/helpers/context.helper.js.map +1 -1
- package/dist/core/common/helpers/db.helper.d.ts +35 -0
- package/dist/core/common/helpers/db.helper.js +345 -0
- package/dist/core/common/helpers/db.helper.js.map +1 -0
- package/dist/core/common/helpers/file.helper.d.ts +8 -1
- package/dist/core/common/helpers/file.helper.js +43 -31
- package/dist/core/common/helpers/file.helper.js.map +1 -1
- package/dist/core/common/helpers/filter.helper.d.ts +3 -0
- package/dist/core/common/helpers/filter.helper.js +93 -81
- package/dist/core/common/helpers/filter.helper.js.map +1 -1
- package/dist/core/common/helpers/graphql.helper.d.ts +24 -1
- package/dist/core/common/helpers/graphql.helper.js +144 -96
- package/dist/core/common/helpers/graphql.helper.js.map +1 -1
- package/dist/core/common/helpers/input.helper.d.ts +29 -3
- package/dist/core/common/helpers/input.helper.js +222 -105
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/helpers/model.helper.d.ts +11 -0
- package/dist/core/common/helpers/model.helper.js +41 -29
- package/dist/core/common/helpers/model.helper.js.map +1 -1
- package/dist/core/common/helpers/service.helper.d.ts +21 -1
- package/dist/core/common/helpers/service.helper.js +80 -72
- package/dist/core/common/helpers/service.helper.js.map +1 -1
- package/dist/core/common/inputs/combined-filter.input.js +1 -1
- package/dist/core/common/inputs/combined-filter.input.js.map +1 -1
- package/dist/core/common/inputs/core-input.input.js +1 -1
- package/dist/core/common/inputs/core-input.input.js.map +1 -1
- package/dist/core/common/interceptors/check-response.interceptor.js +1 -1
- package/dist/core/common/interceptors/check-response.interceptor.js.map +1 -1
- package/dist/core/common/interfaces/resolve-selector.interface.d.ts +5 -0
- package/dist/core/common/interfaces/resolve-selector.interface.js +3 -0
- package/dist/core/common/interfaces/resolve-selector.interface.js.map +1 -0
- package/dist/core/common/interfaces/service-options.interface.d.ts +30 -0
- package/dist/core/common/interfaces/service-options.interface.js +3 -0
- package/dist/core/common/interfaces/service-options.interface.js.map +1 -0
- package/dist/core/common/models/core-model.model.d.ts +4 -0
- package/dist/core/common/models/core-model.model.js +1 -1
- package/dist/core/common/models/core-model.model.js.map +1 -1
- package/dist/core/common/pipes/check-input.pipe.js +2 -2
- package/dist/core/common/pipes/check-input.pipe.js.map +1 -1
- package/dist/core/common/pipes/map-and-validate.pipe.js +1 -1
- package/dist/core/common/pipes/map-and-validate.pipe.js.map +1 -1
- package/dist/core/common/services/crud.service.d.ts +13 -0
- package/dist/core/common/services/crud.service.js +59 -0
- package/dist/core/common/services/crud.service.js.map +1 -0
- package/dist/core/common/services/email.service.js +8 -8
- package/dist/core/common/services/email.service.js.map +1 -1
- package/dist/core/common/services/module.service.d.ts +27 -0
- package/dist/core/common/services/module.service.js +41 -0
- package/dist/core/common/services/module.service.js.map +1 -0
- package/dist/core/common/types/core-model-constructor.type.d.ts +21 -0
- package/dist/core/common/types/core-model-constructor.type.js +3 -0
- package/dist/core/common/types/core-model-constructor.type.js.map +1 -0
- package/dist/core/common/types/field-selection.type.d.ts +4 -0
- package/dist/core/common/types/field-selection.type.js +3 -0
- package/dist/core/common/types/field-selection.type.js.map +1 -0
- package/dist/core/common/types/string-or-object-id.type.d.ts +2 -0
- package/dist/core/common/types/string-or-object-id.type.js +3 -0
- package/dist/core/common/types/string-or-object-id.type.js.map +1 -0
- package/dist/core/modules/auth/core-auth.resolver.d.ts +2 -1
- package/dist/core/modules/auth/core-auth.resolver.js +4 -3
- package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
- package/dist/core/modules/auth/services/core-auth-user.service.d.ts +3 -1
- package/dist/core/modules/auth/services/core-auth-user.service.js.map +1 -1
- package/dist/core/modules/auth/services/core-auth.service.d.ts +2 -1
- package/dist/core/modules/auth/services/core-auth.service.js +6 -4
- package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
- package/dist/core/modules/user/core-user.model.js +1 -1
- package/dist/core/modules/user/core-user.model.js.map +1 -1
- package/dist/core/modules/user/core-user.service.d.ts +16 -25
- package/dist/core/modules/user/core-user.service.js +79 -98
- package/dist/core/modules/user/core-user.service.js.map +1 -1
- package/dist/core.module.js +1 -1
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/server/modules/auth/auth.resolver.d.ts +2 -1
- package/dist/server/modules/auth/auth.resolver.js +4 -3
- package/dist/server/modules/auth/auth.resolver.js.map +1 -1
- package/dist/server/modules/file/file.controller.js +1 -1
- package/dist/server/modules/file/file.controller.js.map +1 -1
- package/dist/server/modules/user/avatar.controller.js +1 -1
- package/dist/server/modules/user/avatar.controller.js.map +1 -1
- package/dist/server/modules/user/user.model.d.ts +1 -0
- package/dist/server/modules/user/user.module.js +7 -3
- package/dist/server/modules/user/user.module.js.map +1 -1
- package/dist/server/modules/user/user.resolver.d.ts +8 -7
- package/dist/server/modules/user/user.resolver.js +65 -45
- package/dist/server/modules/user/user.resolver.js.map +1 -1
- package/dist/server/modules/user/user.service.d.ts +9 -18
- package/dist/server/modules/user/user.service.js +19 -30
- package/dist/server/modules/user/user.service.js.map +1 -1
- package/dist/test/test.helper.d.ts +1 -2
- package/dist/test/test.helper.js +1 -16
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +44 -45
- package/src/core/common/args/pagination.args.ts +2 -2
- package/src/core/common/helpers/config.helper.ts +26 -6
- package/src/core/common/helpers/context.helper.ts +42 -33
- package/src/core/common/helpers/db.helper.ts +580 -0
- package/src/core/common/helpers/file.helper.ts +76 -49
- package/src/core/common/helpers/filter.helper.ts +119 -96
- package/src/core/common/helpers/graphql.helper.ts +219 -117
- package/src/core/common/helpers/input.helper.ts +296 -106
- package/src/core/common/helpers/model.helper.ts +102 -57
- package/src/core/common/helpers/service.helper.ts +149 -117
- package/src/core/common/inputs/combined-filter.input.ts +2 -2
- package/src/core/common/inputs/core-input.input.ts +2 -2
- package/src/core/common/interceptors/check-response.interceptor.ts +2 -2
- package/src/core/common/interfaces/resolve-selector.interface.ts +9 -0
- package/src/core/common/interfaces/service-options.interface.ts +53 -0
- package/src/core/common/models/core-model.model.ts +6 -2
- package/src/core/common/pipes/check-input.pipe.ts +4 -4
- package/src/core/common/pipes/map-and-validate.pipe.ts +2 -2
- package/src/core/common/services/crud.service.ts +105 -0
- package/src/core/common/services/email.service.ts +9 -9
- package/src/core/common/services/module.service.ts +114 -0
- package/src/core/common/types/core-model-constructor.type.ts +30 -0
- package/src/core/common/types/field-selection.type.ts +8 -0
- package/src/core/common/types/string-or-object-id.type.ts +3 -0
- package/src/core/modules/auth/core-auth.module.ts +1 -1
- package/src/core/modules/auth/core-auth.resolver.ts +8 -3
- package/src/core/modules/auth/services/core-auth-user.service.ts +7 -1
- package/src/core/modules/auth/services/core-auth.service.ts +14 -4
- package/src/core/modules/user/core-user.model.ts +2 -1
- package/src/core/modules/user/core-user.service.ts +131 -194
- package/src/core.module.ts +2 -2
- package/src/index.ts +8 -1
- package/src/main.ts +1 -1
- package/src/server/modules/auth/auth.resolver.ts +8 -3
- package/src/server/modules/file/file.controller.ts +2 -2
- package/src/server/modules/user/avatar.controller.ts +2 -2
- package/src/server/modules/user/user.module.ts +7 -3
- package/src/server/modules/user/user.resolver.ts +62 -37
- package/src/server/modules/user/user.service.ts +23 -53
- package/src/test/test.helper.ts +31 -30
- package/dist/core/modules/user/core-basic-user.service.d.ts +0 -17
- package/dist/core/modules/user/core-basic-user.service.js +0 -73
- package/dist/core/modules/user/core-basic-user.service.js.map +0 -1
- package/src/core/modules/user/core-basic-user.service.ts +0 -138
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export default class InputHelper {
|
|
2
2
|
static check(value: any, user: {
|
|
3
3
|
id: any;
|
|
4
4
|
hasRole: (roles: string[]) => boolean;
|
|
5
5
|
}, metatype?: any): Promise<any>;
|
|
6
|
-
static errorFunction(caller: (...params: any[]) => any): void;
|
|
6
|
+
static errorFunction(caller: (...params: any[]) => any, message?: string): void;
|
|
7
7
|
static isArray(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
8
8
|
static isBasicType(metatype: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
9
9
|
static isBetween(parameter: number, min: number, max: number, falseFunction?: (...params: any[]) => any): boolean;
|
|
@@ -14,7 +14,7 @@ export declare class InputHelper {
|
|
|
14
14
|
static isFunction(parameter: (...params: any[]) => any, falseFunction?: (...params: any[]) => any): boolean;
|
|
15
15
|
static isGreater(parameter: number, compare: number, falseFunction?: (...params: any[]) => any): boolean;
|
|
16
16
|
static isLower(parameter: number, compare: number, falseFunction?: (...params: any[]) => any): boolean;
|
|
17
|
-
static isNonEmptyArray(parameter: any,
|
|
17
|
+
static isNonEmptyArray(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
18
18
|
static isNonEmptyObject(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
19
19
|
static isNonEmptyString(parameter: string, falseFunction?: (...params: any[]) => any): boolean;
|
|
20
20
|
static isNumber(parameter: number, falseFunction?: (...params: any[]) => any): boolean;
|
|
@@ -24,3 +24,29 @@ export declare class InputHelper {
|
|
|
24
24
|
static returnFalse(): boolean;
|
|
25
25
|
static map<T>(values: Partial<T>, ctor: new () => T, cloneDeep?: boolean): T;
|
|
26
26
|
}
|
|
27
|
+
export declare function check(value: any, user: {
|
|
28
|
+
id: any;
|
|
29
|
+
hasRole: (roles: string[]) => boolean;
|
|
30
|
+
}, metatype?: any): Promise<any>;
|
|
31
|
+
export declare function errorFunction(caller: (...params: any[]) => any, message?: string): void;
|
|
32
|
+
export declare function isArray(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
33
|
+
export declare function isBasicType(metatype: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
34
|
+
export declare function isBetween(parameter: number, min: number, max: number, falseFunction?: (...params: any[]) => any): boolean;
|
|
35
|
+
export declare function isDate(parameter: Date, falseFunction?: (...params: any[]) => any): boolean;
|
|
36
|
+
export declare function isEmail(parameter: string, falseFunction?: (...params: any[]) => any): boolean;
|
|
37
|
+
export declare function isFalse(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
38
|
+
export declare function isFile(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
39
|
+
export declare function isFunction(parameter: (...params: any[]) => any, falseFunction?: (...params: any[]) => any): boolean;
|
|
40
|
+
export declare function isGreater(parameter: number, compare: number, falseFunction?: (...params: any[]) => any): boolean;
|
|
41
|
+
export declare function isLower(parameter: number, compare: number, falseFunction?: (...params: any[]) => any): boolean;
|
|
42
|
+
export declare function isNonEmptyArray(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
43
|
+
export declare function isNonEmptyObject(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
44
|
+
export declare function isNonEmptyString(parameter: string, falseFunction?: (...params: any[]) => any): boolean;
|
|
45
|
+
export declare function isNumber(parameter: number, falseFunction?: (...params: any[]) => any): boolean;
|
|
46
|
+
export declare function isObject(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
47
|
+
export declare function isTrue(parameter: any, falseFunction?: (...params: any[]) => any): boolean;
|
|
48
|
+
export declare function isString(parameter: string, falseFunction?: (...params: any[]) => any): boolean;
|
|
49
|
+
export declare function returnFalse(): boolean;
|
|
50
|
+
export declare function mapClass<T>(values: Partial<T>, ctor: new () => T, cloneDeep?: boolean): T;
|
|
51
|
+
export declare function typeofArray(arr: any[], strict?: boolean): string;
|
|
52
|
+
export declare function instanceofArray(arr: any[], strict?: boolean): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.instanceofArray = exports.typeofArray = exports.mapClass = exports.returnFalse = exports.isString = exports.isTrue = exports.isObject = exports.isNumber = exports.isNonEmptyString = exports.isNonEmptyObject = exports.isNonEmptyArray = exports.isLower = exports.isGreater = exports.isFunction = exports.isFile = exports.isFalse = exports.isEmail = exports.isDate = exports.isBetween = exports.isBasicType = exports.isArray = exports.errorFunction = exports.check = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const class_transformer_1 = require("class-transformer");
|
|
6
6
|
const class_validator_1 = require("class-validator");
|
|
@@ -8,115 +8,232 @@ const _ = require("lodash");
|
|
|
8
8
|
const restricted_decorator_1 = require("../decorators/restricted.decorator");
|
|
9
9
|
class InputHelper {
|
|
10
10
|
static async check(value, user, metatype) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
11
|
+
return check(value, user, metatype);
|
|
12
|
+
}
|
|
13
|
+
static errorFunction(caller, message = 'Required parameter is missing or invalid') {
|
|
14
|
+
return errorFunction(caller, message);
|
|
15
|
+
}
|
|
16
|
+
static isArray(parameter, falseFunction = errorFunction) {
|
|
17
|
+
return isArray(parameter, falseFunction);
|
|
18
|
+
}
|
|
19
|
+
static isBasicType(metatype, falseFunction = returnFalse) {
|
|
20
|
+
return isBasicType(metatype, falseFunction);
|
|
21
|
+
}
|
|
22
|
+
static isBetween(parameter, min, max, falseFunction = errorFunction) {
|
|
23
|
+
return isBetween(parameter, min, max, falseFunction);
|
|
24
|
+
}
|
|
25
|
+
static isDate(parameter, falseFunction = errorFunction) {
|
|
26
|
+
return isDate(parameter, falseFunction);
|
|
27
|
+
}
|
|
28
|
+
static isEmail(parameter, falseFunction = errorFunction) {
|
|
29
|
+
return isEmail(parameter, falseFunction);
|
|
30
|
+
}
|
|
31
|
+
static isFalse(parameter, falseFunction = errorFunction) {
|
|
32
|
+
return isFalse(parameter, falseFunction);
|
|
33
|
+
}
|
|
34
|
+
static isFile(parameter, falseFunction = errorFunction) {
|
|
35
|
+
return isFile(parameter, falseFunction);
|
|
36
|
+
}
|
|
37
|
+
static isFunction(parameter, falseFunction = errorFunction) {
|
|
38
|
+
return isFunction(parameter, falseFunction);
|
|
28
39
|
}
|
|
29
|
-
static errorFunction
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
static isFalse(parameter, falseFunction = InputHelper.errorFunction) {
|
|
56
|
-
return !parameter ? true : falseFunction(InputHelper.isFalse);
|
|
57
|
-
}
|
|
58
|
-
static isFile(parameter, falseFunction = InputHelper.errorFunction) {
|
|
59
|
-
return parameter !== null &&
|
|
60
|
-
typeof parameter !== 'undefined' &&
|
|
61
|
-
parameter.name &&
|
|
62
|
-
parameter.path &&
|
|
63
|
-
parameter.type &&
|
|
64
|
-
parameter.size > 0
|
|
65
|
-
? true
|
|
66
|
-
: falseFunction(InputHelper.isFile);
|
|
67
|
-
}
|
|
68
|
-
static isFunction(parameter, falseFunction = InputHelper.errorFunction) {
|
|
69
|
-
return typeof parameter === 'function' ? true : falseFunction(InputHelper.isFunction);
|
|
70
|
-
}
|
|
71
|
-
static isGreater(parameter, compare, falseFunction = InputHelper.errorFunction) {
|
|
72
|
-
return typeof parameter === 'number' && parameter > compare ? true : falseFunction(InputHelper.isGreater);
|
|
73
|
-
}
|
|
74
|
-
static isLower(parameter, compare, falseFunction = InputHelper.errorFunction) {
|
|
75
|
-
return typeof parameter === 'number' && parameter < compare ? true : falseFunction(InputHelper.isLower);
|
|
76
|
-
}
|
|
77
|
-
static isNonEmptyArray(parameter, errorFunction = InputHelper.errorFunction) {
|
|
78
|
-
return parameter !== null &&
|
|
79
|
-
typeof parameter !== 'undefined' &&
|
|
80
|
-
parameter.constructor === Array &&
|
|
81
|
-
parameter.length > 0
|
|
82
|
-
? true
|
|
83
|
-
: errorFunction(InputHelper.isNonEmptyArray);
|
|
84
|
-
}
|
|
85
|
-
static isNonEmptyObject(parameter, falseFunction = InputHelper.errorFunction) {
|
|
86
|
-
return parameter !== null &&
|
|
87
|
-
typeof parameter !== 'undefined' &&
|
|
88
|
-
parameter.constructor === Object &&
|
|
89
|
-
Object.keys(parameter).length !== 0
|
|
90
|
-
? true
|
|
91
|
-
: falseFunction(InputHelper.isNonEmptyObject);
|
|
92
|
-
}
|
|
93
|
-
static isNonEmptyString(parameter, falseFunction = InputHelper.errorFunction) {
|
|
94
|
-
return typeof parameter === 'string' && parameter.length > 0 ? true : falseFunction(InputHelper.isNonEmptyString);
|
|
95
|
-
}
|
|
96
|
-
static isNumber(parameter, falseFunction = InputHelper.errorFunction) {
|
|
97
|
-
return typeof parameter === 'number' ? true : falseFunction(InputHelper.isNumber);
|
|
98
|
-
}
|
|
99
|
-
static isObject(parameter, falseFunction = InputHelper.errorFunction) {
|
|
100
|
-
return parameter !== null && typeof parameter !== 'undefined' && parameter.constructor === Object
|
|
101
|
-
? true
|
|
102
|
-
: falseFunction(InputHelper.isObject);
|
|
103
|
-
}
|
|
104
|
-
static isTrue(parameter, falseFunction = InputHelper.errorFunction) {
|
|
105
|
-
return !!parameter ? true : falseFunction(InputHelper.isTrue);
|
|
106
|
-
}
|
|
107
|
-
static isString(parameter, falseFunction = InputHelper.errorFunction) {
|
|
108
|
-
return typeof parameter === 'string' ? true : falseFunction(InputHelper.isString);
|
|
40
|
+
static isGreater(parameter, compare, falseFunction = errorFunction) {
|
|
41
|
+
return isGreater(parameter, compare, falseFunction);
|
|
42
|
+
}
|
|
43
|
+
static isLower(parameter, compare, falseFunction = errorFunction) {
|
|
44
|
+
return isLower(parameter, compare, falseFunction);
|
|
45
|
+
}
|
|
46
|
+
static isNonEmptyArray(parameter, falseFunction = errorFunction) {
|
|
47
|
+
return isNonEmptyString(parameter, errorFunction);
|
|
48
|
+
}
|
|
49
|
+
static isNonEmptyObject(parameter, falseFunction = errorFunction) {
|
|
50
|
+
return isNonEmptyObject(parameter, falseFunction);
|
|
51
|
+
}
|
|
52
|
+
static isNonEmptyString(parameter, falseFunction = errorFunction) {
|
|
53
|
+
return isNonEmptyString(parameter, falseFunction);
|
|
54
|
+
}
|
|
55
|
+
static isNumber(parameter, falseFunction = errorFunction) {
|
|
56
|
+
return isNumber(parameter, falseFunction);
|
|
57
|
+
}
|
|
58
|
+
static isObject(parameter, falseFunction = errorFunction) {
|
|
59
|
+
return isObject(parameter, falseFunction);
|
|
60
|
+
}
|
|
61
|
+
static isTrue(parameter, falseFunction = errorFunction) {
|
|
62
|
+
return isTrue(parameter, falseFunction);
|
|
63
|
+
}
|
|
64
|
+
static isString(parameter, falseFunction = errorFunction) {
|
|
65
|
+
return isString(parameter, falseFunction);
|
|
109
66
|
}
|
|
110
67
|
static returnFalse() {
|
|
111
|
-
return
|
|
68
|
+
return returnFalse();
|
|
112
69
|
}
|
|
113
70
|
static map(values, ctor, cloneDeep = true) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
71
|
+
return mapClass(values, ctor);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.default = InputHelper;
|
|
75
|
+
async function check(value, user, metatype) {
|
|
76
|
+
if (typeof value !== 'object' || !metatype || isBasicType(metatype)) {
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
if (!(value instanceof metatype)) {
|
|
80
|
+
if (metatype === null || metatype === void 0 ? void 0 : metatype.map) {
|
|
81
|
+
value = metatype === null || metatype === void 0 ? void 0 : metatype.map(value);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
value = (0, class_transformer_1.plainToInstance)(metatype, value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const errors = await (0, class_validator_1.validate)(value);
|
|
88
|
+
if (errors.length > 0) {
|
|
89
|
+
throw new common_1.BadRequestException('Validation failed');
|
|
90
|
+
}
|
|
91
|
+
value = (0, restricted_decorator_1.checkRestricted)(value, user);
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
exports.check = check;
|
|
95
|
+
function errorFunction(caller, message = 'Required parameter is missing or invalid') {
|
|
96
|
+
const err = new Error(message);
|
|
97
|
+
Error.captureStackTrace(err, caller);
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
exports.errorFunction = errorFunction;
|
|
101
|
+
function isArray(parameter, falseFunction = errorFunction) {
|
|
102
|
+
return Array.isArray(parameter) ? true : falseFunction(isArray);
|
|
103
|
+
}
|
|
104
|
+
exports.isArray = isArray;
|
|
105
|
+
function isBasicType(metatype, falseFunction = returnFalse) {
|
|
106
|
+
const types = [String, Boolean, Number, Array, Object, Buffer, ArrayBuffer];
|
|
107
|
+
return types.includes(metatype) ? true : falseFunction(isBasicType);
|
|
108
|
+
}
|
|
109
|
+
exports.isBasicType = isBasicType;
|
|
110
|
+
function isBetween(parameter, min, max, falseFunction = errorFunction) {
|
|
111
|
+
return typeof parameter === 'number' && parameter > min && parameter < max ? true : falseFunction(isBetween);
|
|
112
|
+
}
|
|
113
|
+
exports.isBetween = isBetween;
|
|
114
|
+
function isDate(parameter, falseFunction = errorFunction) {
|
|
115
|
+
return parameter instanceof Date ? true : falseFunction(isDate);
|
|
116
|
+
}
|
|
117
|
+
exports.isDate = isDate;
|
|
118
|
+
function isEmail(parameter, falseFunction = errorFunction) {
|
|
119
|
+
const regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
|
|
120
|
+
return regex.test(parameter) ? true : falseFunction(isEmail);
|
|
121
|
+
}
|
|
122
|
+
exports.isEmail = isEmail;
|
|
123
|
+
function isFalse(parameter, falseFunction = errorFunction) {
|
|
124
|
+
return !parameter ? true : falseFunction(isFalse);
|
|
125
|
+
}
|
|
126
|
+
exports.isFalse = isFalse;
|
|
127
|
+
function isFile(parameter, falseFunction = errorFunction) {
|
|
128
|
+
return parameter !== null &&
|
|
129
|
+
typeof parameter !== 'undefined' &&
|
|
130
|
+
parameter.name &&
|
|
131
|
+
parameter.path &&
|
|
132
|
+
parameter.type &&
|
|
133
|
+
parameter.size > 0
|
|
134
|
+
? true
|
|
135
|
+
: falseFunction(isFile);
|
|
136
|
+
}
|
|
137
|
+
exports.isFile = isFile;
|
|
138
|
+
function isFunction(parameter, falseFunction = errorFunction) {
|
|
139
|
+
return typeof parameter === 'function' ? true : falseFunction(isFunction);
|
|
140
|
+
}
|
|
141
|
+
exports.isFunction = isFunction;
|
|
142
|
+
function isGreater(parameter, compare, falseFunction = errorFunction) {
|
|
143
|
+
return typeof parameter === 'number' && parameter > compare ? true : falseFunction(isGreater);
|
|
144
|
+
}
|
|
145
|
+
exports.isGreater = isGreater;
|
|
146
|
+
function isLower(parameter, compare, falseFunction = errorFunction) {
|
|
147
|
+
return typeof parameter === 'number' && parameter < compare ? true : falseFunction(isLower);
|
|
148
|
+
}
|
|
149
|
+
exports.isLower = isLower;
|
|
150
|
+
function isNonEmptyArray(parameter, falseFunction = errorFunction) {
|
|
151
|
+
return parameter !== null &&
|
|
152
|
+
typeof parameter !== 'undefined' &&
|
|
153
|
+
parameter.constructor === Array &&
|
|
154
|
+
parameter.length > 0
|
|
155
|
+
? true
|
|
156
|
+
: falseFunction(isNonEmptyArray);
|
|
157
|
+
}
|
|
158
|
+
exports.isNonEmptyArray = isNonEmptyArray;
|
|
159
|
+
function isNonEmptyObject(parameter, falseFunction = errorFunction) {
|
|
160
|
+
return parameter !== null &&
|
|
161
|
+
typeof parameter !== 'undefined' &&
|
|
162
|
+
parameter.constructor === Object &&
|
|
163
|
+
Object.keys(parameter).length !== 0
|
|
164
|
+
? true
|
|
165
|
+
: falseFunction(isNonEmptyObject);
|
|
166
|
+
}
|
|
167
|
+
exports.isNonEmptyObject = isNonEmptyObject;
|
|
168
|
+
function isNonEmptyString(parameter, falseFunction = errorFunction) {
|
|
169
|
+
return typeof parameter === 'string' && parameter.length > 0 ? true : falseFunction(isNonEmptyString);
|
|
170
|
+
}
|
|
171
|
+
exports.isNonEmptyString = isNonEmptyString;
|
|
172
|
+
function isNumber(parameter, falseFunction = errorFunction) {
|
|
173
|
+
return typeof parameter === 'number' ? true : falseFunction(isNumber);
|
|
174
|
+
}
|
|
175
|
+
exports.isNumber = isNumber;
|
|
176
|
+
function isObject(parameter, falseFunction = errorFunction) {
|
|
177
|
+
return parameter !== null && typeof parameter !== 'undefined' && parameter.constructor === Object
|
|
178
|
+
? true
|
|
179
|
+
: falseFunction(isObject);
|
|
180
|
+
}
|
|
181
|
+
exports.isObject = isObject;
|
|
182
|
+
function isTrue(parameter, falseFunction = errorFunction) {
|
|
183
|
+
return !!parameter ? true : falseFunction(isTrue);
|
|
184
|
+
}
|
|
185
|
+
exports.isTrue = isTrue;
|
|
186
|
+
function isString(parameter, falseFunction = errorFunction) {
|
|
187
|
+
return typeof parameter === 'string' ? true : falseFunction(isString);
|
|
188
|
+
}
|
|
189
|
+
exports.isString = isString;
|
|
190
|
+
function returnFalse() {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
exports.returnFalse = returnFalse;
|
|
194
|
+
function mapClass(values, ctor, cloneDeep = true) {
|
|
195
|
+
const instance = new ctor();
|
|
196
|
+
return Object.keys(instance).reduce((obj, key) => {
|
|
197
|
+
obj[key] = cloneDeep ? _.cloneDeep(values[key]) : values[key];
|
|
198
|
+
return obj;
|
|
199
|
+
}, instance);
|
|
200
|
+
}
|
|
201
|
+
exports.mapClass = mapClass;
|
|
202
|
+
function typeofArray(arr, strict = false) {
|
|
203
|
+
let type = undefined;
|
|
204
|
+
if (!(arr === null || arr === void 0 ? void 0 : arr.length)) {
|
|
205
|
+
return type;
|
|
206
|
+
}
|
|
207
|
+
type = typeof arr[0];
|
|
208
|
+
if (strict) {
|
|
209
|
+
for (const item of arr) {
|
|
210
|
+
if (typeof item !== type) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return type;
|
|
216
|
+
}
|
|
217
|
+
exports.typeofArray = typeofArray;
|
|
218
|
+
function instanceofArray(arr, strict = false) {
|
|
219
|
+
let constructor = undefined;
|
|
220
|
+
if (!(arr === null || arr === void 0 ? void 0 : arr.length)) {
|
|
221
|
+
return constructor;
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
constructor = arr[0].constructor;
|
|
225
|
+
if (strict) {
|
|
226
|
+
for (const item of arr) {
|
|
227
|
+
if (item.constructor !== constructor) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
return undefined;
|
|
119
235
|
}
|
|
236
|
+
return constructor;
|
|
120
237
|
}
|
|
121
|
-
exports.
|
|
238
|
+
exports.instanceofArray = instanceofArray;
|
|
122
239
|
//# sourceMappingURL=input.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/input.helper.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AACrD,yDAAoD;AACpD,qDAA2C;AAC3C,4BAA4B;AAC5B,6EAAqE;
|
|
1
|
+
{"version":3,"file":"input.helper.js","sourceRoot":"","sources":["../../../../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,CAAC,CAAC;IACrB,IAAI,MAAM,EAAE;QACV,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE;YACtB,IAAI,OAAO,IAAI,KAAK,IAAI,EAAE;gBACxB,OAAO,SAAS,CAAC;aAClB;SACF;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAdD,kCAcC;AAKD,SAAgB,eAAe,CAAC,GAAU,EAAE,MAAM,GAAG,KAAK;IACxD,IAAI,WAAW,GAAW,SAAS,CAAC;IACpC,IAAI,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,CAAA,EAAE;QAChB,OAAO,WAAW,CAAC;KACpB;IACD,IAAI;QACF,WAAW,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QACjC,IAAI,MAAM,EAAE;YACV,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE;gBACtB,IAAI,IAAI,CAAC,WAAW,KAAK,WAAW,EAAE;oBACpC,OAAO,SAAS,CAAC;iBAClB;aACF;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAlBD,0CAkBC"}
|
|
@@ -11,3 +11,14 @@ export declare class ModelHelper {
|
|
|
11
11
|
}): T;
|
|
12
12
|
static maps<T = Record<string, any>>(data: Partial<T> | Partial<T>[] | Record<string, any> | Record<string, any>[], targetClass: new (...args: any[]) => T, cloneDeep?: boolean): T[];
|
|
13
13
|
}
|
|
14
|
+
export declare function prepareMap<T = Record<string, any>>(source: Partial<T> | Record<string, any>, target: T, options?: {
|
|
15
|
+
cloneDeep?: boolean;
|
|
16
|
+
funcAllowed?: boolean;
|
|
17
|
+
mapId?: boolean;
|
|
18
|
+
}): Partial<T> | Record<string, any>;
|
|
19
|
+
export declare function map<T = Record<string, any>>(source: Partial<T> | Record<string, any>, target: T, options?: {
|
|
20
|
+
cloneDeep?: boolean;
|
|
21
|
+
funcAllowed?: boolean;
|
|
22
|
+
mapId?: boolean;
|
|
23
|
+
}): T;
|
|
24
|
+
export declare function maps<T = Record<string, any>>(data: Partial<T> | Partial<T>[] | Record<string, any> | Record<string, any>[], targetClass: new (...args: any[]) => T, cloneDeep?: boolean): T[];
|
|
@@ -1,43 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelHelper = void 0;
|
|
3
|
+
exports.maps = exports.map = exports.prepareMap = exports.ModelHelper = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
class ModelHelper {
|
|
6
6
|
static prepareMap(source, target, options = {}) {
|
|
7
|
-
|
|
8
|
-
const result = {};
|
|
9
|
-
for (const key of Object.keys(target)) {
|
|
10
|
-
if ((!['id', '_id'].includes(key) || config.mapId) &&
|
|
11
|
-
source[key] !== undefined &&
|
|
12
|
-
(config.funcAllowed || typeof (source[key] !== 'function'))) {
|
|
13
|
-
result[key] = source[key] !== 'function' && config.cloneDeep ? _.cloneDeep(source[key]) : source[key];
|
|
14
|
-
}
|
|
15
|
-
else if (key === 'id' && !config.mapId) {
|
|
16
|
-
result['id'] = source[key];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
7
|
+
return prepareMap(source, target, options);
|
|
20
8
|
}
|
|
21
9
|
static map(source, target, options = {}) {
|
|
22
|
-
|
|
23
|
-
if (!source || typeof source !== 'object' || Array.isArray(source)) {
|
|
24
|
-
return config.cloneDeep ? _.cloneDeep(target) : target;
|
|
25
|
-
}
|
|
26
|
-
const preparedSource = ModelHelper.prepareMap(source, target, config);
|
|
27
|
-
Object.assign(target, preparedSource);
|
|
28
|
-
return target;
|
|
10
|
+
return map(source, target, options);
|
|
29
11
|
}
|
|
30
12
|
static maps(data, targetClass, cloneDeep = true) {
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
return maps(data, targetClass, cloneDeep);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ModelHelper = ModelHelper;
|
|
17
|
+
function prepareMap(source, target, options = {}) {
|
|
18
|
+
const config = Object.assign({ cloneDeep: true, funcAllowed: false, mapId: false }, options);
|
|
19
|
+
const result = {};
|
|
20
|
+
for (const key of Object.keys(target)) {
|
|
21
|
+
if ((!['id', '_id'].includes(key) || config.mapId) &&
|
|
22
|
+
source[key] !== undefined &&
|
|
23
|
+
(config.funcAllowed || typeof (source[key] !== 'function'))) {
|
|
24
|
+
result[key] = source[key] !== 'function' && config.cloneDeep ? _.cloneDeep(source[key]) : source[key];
|
|
33
25
|
}
|
|
34
|
-
if (!
|
|
35
|
-
|
|
26
|
+
else if (key === 'id' && !config.mapId) {
|
|
27
|
+
result['id'] = source[key];
|
|
36
28
|
}
|
|
37
|
-
return data.map((item) => {
|
|
38
|
-
return targetClass.map(item, { cloneDeep });
|
|
39
|
-
});
|
|
40
29
|
}
|
|
30
|
+
return result;
|
|
41
31
|
}
|
|
42
|
-
exports.
|
|
32
|
+
exports.prepareMap = prepareMap;
|
|
33
|
+
function map(source, target, options = {}) {
|
|
34
|
+
const config = Object.assign({ cloneDeep: true, funcAllowed: false, mapId: false }, options);
|
|
35
|
+
if (!source || typeof source !== 'object' || Array.isArray(source)) {
|
|
36
|
+
return config.cloneDeep ? _.cloneDeep(target) : target;
|
|
37
|
+
}
|
|
38
|
+
const preparedSource = prepareMap(source, target, config);
|
|
39
|
+
Object.assign(target, preparedSource);
|
|
40
|
+
return target;
|
|
41
|
+
}
|
|
42
|
+
exports.map = map;
|
|
43
|
+
function maps(data, targetClass, cloneDeep = true) {
|
|
44
|
+
if (!data || typeof data !== 'object') {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (!Array.isArray(data)) {
|
|
48
|
+
data = [data];
|
|
49
|
+
}
|
|
50
|
+
return data.map((item) => {
|
|
51
|
+
return targetClass.map(item, { cloneDeep });
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.maps = maps;
|
|
43
55
|
//# sourceMappingURL=model.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/model.helper.ts"],"names":[],"mappings":";;;AAAA,4BAA4B;
|
|
1
|
+
{"version":3,"file":"model.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/model.helper.ts"],"names":[],"mappings":";;;AAAA,4BAA4B;AAM5B,MAAa,WAAW;IAOf,MAAM,CAAC,UAAU,CACtB,MAAwC,EACxC,MAAS,EACT,UAII,EAAE;QAEN,OAAO,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAKM,MAAM,CAAC,GAAG,CACf,MAAwC,EACxC,MAAS,EACT,UAII,EAAE;QAEN,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAKM,MAAM,CAAC,IAAI,CAChB,IAA6E,EAC7E,WAAsC,EACtC,SAAS,GAAG,IAAI;QAEhB,OAAO,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IAC5C,CAAC;CACF;AA5CD,kCA4CC;AAQD,SAAgB,UAAU,CACxB,MAAwC,EACxC,MAAS,EACT,UAII,EAAE;IAGN,MAAM,MAAM,mBACV,SAAS,EAAE,IAAI,EACf,WAAW,EAAE,KAAK,EAClB,KAAK,EAAE,KAAK,IACT,OAAO,CACX,CAAC;IAGF,MAAM,MAAM,GAAG,EAAE,CAAC;IAGlB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACrC,IACE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC;YAC9C,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS;YACzB,CAAC,MAAM,CAAC,WAAW,IAAI,OAAO,CAAC,M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,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACxB,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;KACf;IAGD,OAAQ,IAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAClC,OAAQ,WAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC;AAnBD,oBAmBC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export default class ServiceHelper {
|
|
2
2
|
static prepareInput<T = any>(input: T, currentUser: {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
id: string;
|
|
@@ -20,3 +20,23 @@ export declare class ServiceHelper {
|
|
|
20
20
|
targetModel?: new (...args: any[]) => T;
|
|
21
21
|
}): Promise<T | T[] | any>;
|
|
22
22
|
}
|
|
23
|
+
export declare function prepareInput<T = any>(input: T, currentUser: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
id: string;
|
|
26
|
+
}, options?: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
create?: boolean;
|
|
29
|
+
clone?: boolean;
|
|
30
|
+
getNewArray?: boolean;
|
|
31
|
+
removeUndefined?: boolean;
|
|
32
|
+
}): Promise<T>;
|
|
33
|
+
export declare function prepareOutput<T = {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
map: (...args: any[]) => any;
|
|
36
|
+
}>(output: any, options?: {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
clone?: boolean;
|
|
39
|
+
getNewArray?: boolean;
|
|
40
|
+
removeUndefined?: boolean;
|
|
41
|
+
targetModel?: new (...args: any[]) => T;
|
|
42
|
+
}): Promise<T | T[] | any>;
|