@lenne.tech/nest-server 8.0.2 → 8.3.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/config.env.js +3 -2
- package/dist/config.env.js.map +1 -1
- 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/decorators/restricted.decorator.d.ts +3 -0
- package/dist/core/common/decorators/restricted.decorator.js +14 -8
- package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
- package/dist/core/common/enums/role.enum.d.ts +3 -2
- package/dist/core/common/enums/role.enum.js +3 -2
- package/dist/core/common/enums/role.enum.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 +37 -0
- package/dist/core/common/helpers/db.helper.js +356 -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 +42 -4
- package/dist/core/common/helpers/input.helper.js +256 -97
- 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 +36 -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 +5 -1
- 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 +57 -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 +40 -0
- package/dist/core/common/services/module.service.js +80 -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/ids.type.d.ts +8 -0
- package/dist/core/common/types/ids.type.js +3 -0
- package/dist/core/common/types/ids.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/guards/roles.guard.js +1 -2
- package/dist/core/modules/auth/guards/roles.guard.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 +69 -90
- 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 +9 -1
- package/dist/index.js +9 -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 +2 -2
- package/dist/server/modules/user/avatar.controller.js.map +1 -1
- package/dist/server/modules/user/user.model.d.ts +2 -1
- 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 +85 -49
- 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 +23 -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 +58 -59
- package/src/config.env.ts +3 -2
- package/src/core/common/args/pagination.args.ts +2 -2
- package/src/core/common/decorators/restricted.decorator.ts +24 -12
- package/src/core/common/enums/role.enum.ts +23 -5
- 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 +595 -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 +349 -108
- 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 +71 -0
- package/src/core/common/models/core-model.model.ts +7 -3
- 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 +100 -0
- package/src/core/common/services/email.service.ts +9 -9
- package/src/core/common/services/module.service.ts +188 -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/ids.type.ts +7 -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/guards/roles.guard.ts +5 -7
- 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 +115 -185
- package/src/core.module.ts +2 -2
- package/src/index.ts +9 -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 +3 -3
- package/src/server/modules/user/user.module.ts +7 -3
- package/src/server/modules/user/user.resolver.ts +74 -43
- package/src/server/modules/user/user.service.ts +30 -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,14 +1,120 @@
|
|
|
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");
|
|
7
7
|
const _ = require("lodash");
|
|
8
8
|
const restricted_decorator_1 = require("../decorators/restricted.decorator");
|
|
9
|
+
const role_enum_1 = require("../enums/role.enum");
|
|
10
|
+
const db_helper_1 = require("./db.helper");
|
|
9
11
|
class InputHelper {
|
|
10
|
-
static async check(value, user,
|
|
11
|
-
|
|
12
|
+
static async check(value, user, options) {
|
|
13
|
+
return check(value, user, options);
|
|
14
|
+
}
|
|
15
|
+
static errorFunction(caller, message = 'Required parameter is missing or invalid') {
|
|
16
|
+
return errorFunction(caller, message);
|
|
17
|
+
}
|
|
18
|
+
static isArray(parameter, falseFunction = errorFunction) {
|
|
19
|
+
return isArray(parameter, falseFunction);
|
|
20
|
+
}
|
|
21
|
+
static isBasicType(metatype, falseFunction = returnFalse) {
|
|
22
|
+
return isBasicType(metatype, falseFunction);
|
|
23
|
+
}
|
|
24
|
+
static isBetween(parameter, min, max, falseFunction = errorFunction) {
|
|
25
|
+
return isBetween(parameter, min, max, falseFunction);
|
|
26
|
+
}
|
|
27
|
+
static isDate(parameter, falseFunction = errorFunction) {
|
|
28
|
+
return isDate(parameter, falseFunction);
|
|
29
|
+
}
|
|
30
|
+
static isEmail(parameter, falseFunction = errorFunction) {
|
|
31
|
+
return isEmail(parameter, falseFunction);
|
|
32
|
+
}
|
|
33
|
+
static isFalse(parameter, falseFunction = errorFunction) {
|
|
34
|
+
return isFalse(parameter, falseFunction);
|
|
35
|
+
}
|
|
36
|
+
static isFile(parameter, falseFunction = errorFunction) {
|
|
37
|
+
return isFile(parameter, falseFunction);
|
|
38
|
+
}
|
|
39
|
+
static isFunction(parameter, falseFunction = errorFunction) {
|
|
40
|
+
return isFunction(parameter, falseFunction);
|
|
41
|
+
}
|
|
42
|
+
static isGreater(parameter, compare, falseFunction = errorFunction) {
|
|
43
|
+
return isGreater(parameter, compare, falseFunction);
|
|
44
|
+
}
|
|
45
|
+
static isLower(parameter, compare, falseFunction = errorFunction) {
|
|
46
|
+
return isLower(parameter, compare, falseFunction);
|
|
47
|
+
}
|
|
48
|
+
static isNonEmptyArray(parameter, falseFunction = errorFunction) {
|
|
49
|
+
return isNonEmptyString(parameter, errorFunction);
|
|
50
|
+
}
|
|
51
|
+
static isNonEmptyObject(parameter, falseFunction = errorFunction) {
|
|
52
|
+
return isNonEmptyObject(parameter, falseFunction);
|
|
53
|
+
}
|
|
54
|
+
static isNonEmptyString(parameter, falseFunction = errorFunction) {
|
|
55
|
+
return isNonEmptyString(parameter, falseFunction);
|
|
56
|
+
}
|
|
57
|
+
static isNumber(parameter, falseFunction = errorFunction) {
|
|
58
|
+
return isNumber(parameter, falseFunction);
|
|
59
|
+
}
|
|
60
|
+
static isObject(parameter, falseFunction = errorFunction) {
|
|
61
|
+
return isObject(parameter, falseFunction);
|
|
62
|
+
}
|
|
63
|
+
static isTrue(parameter, falseFunction = errorFunction) {
|
|
64
|
+
return isTrue(parameter, falseFunction);
|
|
65
|
+
}
|
|
66
|
+
static isString(parameter, falseFunction = errorFunction) {
|
|
67
|
+
return isString(parameter, falseFunction);
|
|
68
|
+
}
|
|
69
|
+
static returnFalse() {
|
|
70
|
+
return returnFalse();
|
|
71
|
+
}
|
|
72
|
+
static map(values, ctor, cloneDeep = true) {
|
|
73
|
+
return mapClass(values, ctor);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.default = InputHelper;
|
|
77
|
+
async function check(value, user, options) {
|
|
78
|
+
var _a;
|
|
79
|
+
const config = Object.assign({ throwError: true }, options);
|
|
80
|
+
if (((_a = config.roles) === null || _a === void 0 ? void 0 : _a.length) && config.throwError) {
|
|
81
|
+
let roles = config.roles;
|
|
82
|
+
if (!Array.isArray(roles)) {
|
|
83
|
+
roles = [roles];
|
|
84
|
+
}
|
|
85
|
+
let valid = false;
|
|
86
|
+
if (roles.includes(role_enum_1.RoleEnum.S_USER) && (user === null || user === void 0 ? void 0 : user.id)) {
|
|
87
|
+
valid = true;
|
|
88
|
+
}
|
|
89
|
+
else if (user.hasRole(roles)) {
|
|
90
|
+
valid = true;
|
|
91
|
+
}
|
|
92
|
+
else if (roles.includes(role_enum_1.RoleEnum.S_CREATOR) && (user === null || user === void 0 ? void 0 : user.id) && (0, db_helper_1.equalIds)(user.id, config.creator)) {
|
|
93
|
+
valid = true;
|
|
94
|
+
}
|
|
95
|
+
else if (roles.includes(role_enum_1.RoleEnum.S_OWNER) && (user === null || user === void 0 ? void 0 : user.id) && config.ownerIds) {
|
|
96
|
+
let ownerIds = (0, db_helper_1.getStringIds)(config.ownerIds);
|
|
97
|
+
if (!Array.isArray(ownerIds)) {
|
|
98
|
+
ownerIds = [ownerIds];
|
|
99
|
+
}
|
|
100
|
+
valid = ownerIds.includes((0, db_helper_1.getStringIds)(user.id));
|
|
101
|
+
}
|
|
102
|
+
if (!valid) {
|
|
103
|
+
throw new common_1.UnauthorizedException('Missing rights');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (typeof value !== 'object') {
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
for (const [key, item] of Object.entries(value)) {
|
|
111
|
+
value[key] = await check(item, user, config);
|
|
112
|
+
}
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
const metatype = config.metatype;
|
|
116
|
+
if (metatype) {
|
|
117
|
+
if (isBasicType(metatype)) {
|
|
12
118
|
return value;
|
|
13
119
|
}
|
|
14
120
|
if (!(value instanceof metatype)) {
|
|
@@ -19,104 +125,157 @@ class InputHelper {
|
|
|
19
125
|
value = (0, class_transformer_1.plainToInstance)(metatype, value);
|
|
20
126
|
}
|
|
21
127
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
128
|
+
}
|
|
129
|
+
const errors = await (0, class_validator_1.validate)(value);
|
|
130
|
+
if (errors.length > 0 && config.throwError) {
|
|
131
|
+
throw new common_1.BadRequestException('Validation failed');
|
|
132
|
+
}
|
|
133
|
+
value = (0, restricted_decorator_1.checkRestricted)(value, user, config);
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
exports.check = check;
|
|
137
|
+
function errorFunction(caller, message = 'Required parameter is missing or invalid') {
|
|
138
|
+
const err = new Error(message);
|
|
139
|
+
Error.captureStackTrace(err, caller);
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
exports.errorFunction = errorFunction;
|
|
143
|
+
function isArray(parameter, falseFunction = errorFunction) {
|
|
144
|
+
return Array.isArray(parameter) ? true : falseFunction(isArray);
|
|
145
|
+
}
|
|
146
|
+
exports.isArray = isArray;
|
|
147
|
+
function isBasicType(metatype, falseFunction = returnFalse) {
|
|
148
|
+
const types = [String, Boolean, Number, Array, Object, Buffer, ArrayBuffer];
|
|
149
|
+
return types.includes(metatype) ? true : falseFunction(isBasicType);
|
|
150
|
+
}
|
|
151
|
+
exports.isBasicType = isBasicType;
|
|
152
|
+
function isBetween(parameter, min, max, falseFunction = errorFunction) {
|
|
153
|
+
return typeof parameter === 'number' && parameter > min && parameter < max ? true : falseFunction(isBetween);
|
|
154
|
+
}
|
|
155
|
+
exports.isBetween = isBetween;
|
|
156
|
+
function isDate(parameter, falseFunction = errorFunction) {
|
|
157
|
+
return parameter instanceof Date ? true : falseFunction(isDate);
|
|
158
|
+
}
|
|
159
|
+
exports.isDate = isDate;
|
|
160
|
+
function isEmail(parameter, falseFunction = errorFunction) {
|
|
161
|
+
const regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
|
|
162
|
+
return regex.test(parameter) ? true : falseFunction(isEmail);
|
|
163
|
+
}
|
|
164
|
+
exports.isEmail = isEmail;
|
|
165
|
+
function isFalse(parameter, falseFunction = errorFunction) {
|
|
166
|
+
return !parameter ? true : falseFunction(isFalse);
|
|
167
|
+
}
|
|
168
|
+
exports.isFalse = isFalse;
|
|
169
|
+
function isFile(parameter, falseFunction = errorFunction) {
|
|
170
|
+
return parameter !== null &&
|
|
171
|
+
typeof parameter !== 'undefined' &&
|
|
172
|
+
parameter.name &&
|
|
173
|
+
parameter.path &&
|
|
174
|
+
parameter.type &&
|
|
175
|
+
parameter.size > 0
|
|
176
|
+
? true
|
|
177
|
+
: falseFunction(isFile);
|
|
178
|
+
}
|
|
179
|
+
exports.isFile = isFile;
|
|
180
|
+
function isFunction(parameter, falseFunction = errorFunction) {
|
|
181
|
+
return typeof parameter === 'function' ? true : falseFunction(isFunction);
|
|
182
|
+
}
|
|
183
|
+
exports.isFunction = isFunction;
|
|
184
|
+
function isGreater(parameter, compare, falseFunction = errorFunction) {
|
|
185
|
+
return typeof parameter === 'number' && parameter > compare ? true : falseFunction(isGreater);
|
|
186
|
+
}
|
|
187
|
+
exports.isGreater = isGreater;
|
|
188
|
+
function isLower(parameter, compare, falseFunction = errorFunction) {
|
|
189
|
+
return typeof parameter === 'number' && parameter < compare ? true : falseFunction(isLower);
|
|
190
|
+
}
|
|
191
|
+
exports.isLower = isLower;
|
|
192
|
+
function isNonEmptyArray(parameter, falseFunction = errorFunction) {
|
|
193
|
+
return parameter !== null &&
|
|
194
|
+
typeof parameter !== 'undefined' &&
|
|
195
|
+
parameter.constructor === Array &&
|
|
196
|
+
parameter.length > 0
|
|
197
|
+
? true
|
|
198
|
+
: falseFunction(isNonEmptyArray);
|
|
199
|
+
}
|
|
200
|
+
exports.isNonEmptyArray = isNonEmptyArray;
|
|
201
|
+
function isNonEmptyObject(parameter, falseFunction = errorFunction) {
|
|
202
|
+
return parameter !== null &&
|
|
203
|
+
typeof parameter !== 'undefined' &&
|
|
204
|
+
parameter.constructor === Object &&
|
|
205
|
+
Object.keys(parameter).length !== 0
|
|
206
|
+
? true
|
|
207
|
+
: falseFunction(isNonEmptyObject);
|
|
208
|
+
}
|
|
209
|
+
exports.isNonEmptyObject = isNonEmptyObject;
|
|
210
|
+
function isNonEmptyString(parameter, falseFunction = errorFunction) {
|
|
211
|
+
return typeof parameter === 'string' && parameter.length > 0 ? true : falseFunction(isNonEmptyString);
|
|
212
|
+
}
|
|
213
|
+
exports.isNonEmptyString = isNonEmptyString;
|
|
214
|
+
function isNumber(parameter, falseFunction = errorFunction) {
|
|
215
|
+
return typeof parameter === 'number' ? true : falseFunction(isNumber);
|
|
216
|
+
}
|
|
217
|
+
exports.isNumber = isNumber;
|
|
218
|
+
function isObject(parameter, falseFunction = errorFunction) {
|
|
219
|
+
return parameter !== null && typeof parameter !== 'undefined' && parameter.constructor === Object
|
|
220
|
+
? true
|
|
221
|
+
: falseFunction(isObject);
|
|
222
|
+
}
|
|
223
|
+
exports.isObject = isObject;
|
|
224
|
+
function isTrue(parameter, falseFunction = errorFunction) {
|
|
225
|
+
return !!parameter ? true : falseFunction(isTrue);
|
|
226
|
+
}
|
|
227
|
+
exports.isTrue = isTrue;
|
|
228
|
+
function isString(parameter, falseFunction = errorFunction) {
|
|
229
|
+
return typeof parameter === 'string' ? true : falseFunction(isString);
|
|
230
|
+
}
|
|
231
|
+
exports.isString = isString;
|
|
232
|
+
function returnFalse() {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
exports.returnFalse = returnFalse;
|
|
236
|
+
function mapClass(values, ctor, cloneDeep = true) {
|
|
237
|
+
const instance = new ctor();
|
|
238
|
+
return Object.keys(instance).reduce((obj, key) => {
|
|
239
|
+
obj[key] = cloneDeep ? _.cloneDeep(values[key]) : values[key];
|
|
240
|
+
return obj;
|
|
241
|
+
}, instance);
|
|
242
|
+
}
|
|
243
|
+
exports.mapClass = mapClass;
|
|
244
|
+
function typeofArray(arr, strict = false) {
|
|
245
|
+
let type = undefined;
|
|
246
|
+
if (!(arr === null || arr === void 0 ? void 0 : arr.length)) {
|
|
247
|
+
return type;
|
|
248
|
+
}
|
|
249
|
+
type = typeof arr[0];
|
|
250
|
+
if (strict) {
|
|
251
|
+
for (const item of arr) {
|
|
252
|
+
if (typeof item !== type) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
25
255
|
}
|
|
26
|
-
value = (0, restricted_decorator_1.checkRestricted)(value, user);
|
|
27
|
-
return value;
|
|
28
256
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
? true
|
|
37
|
-
: falseFunction(InputHelper.isArray);
|
|
38
|
-
}
|
|
39
|
-
static isBasicType(metatype, falseFunction = InputHelper.returnFalse) {
|
|
40
|
-
const types = [String, Boolean, Number, Array, Object, Buffer, ArrayBuffer];
|
|
41
|
-
return types.includes(metatype) ? true : falseFunction(InputHelper.isBasicType);
|
|
42
|
-
}
|
|
43
|
-
static isBetween(parameter, min, max, falseFunction = InputHelper.errorFunction) {
|
|
44
|
-
return typeof parameter === 'number' && parameter > min && parameter < max
|
|
45
|
-
? true
|
|
46
|
-
: falseFunction(InputHelper.isBetween);
|
|
47
|
-
}
|
|
48
|
-
static isDate(parameter, falseFunction = InputHelper.errorFunction) {
|
|
49
|
-
return parameter instanceof Date ? true : falseFunction(InputHelper.isDate);
|
|
50
|
-
}
|
|
51
|
-
static isEmail(parameter, falseFunction = InputHelper.errorFunction) {
|
|
52
|
-
const regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
|
|
53
|
-
return regex.test(parameter) ? true : falseFunction(InputHelper.isEmail);
|
|
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);
|
|
257
|
+
return type;
|
|
258
|
+
}
|
|
259
|
+
exports.typeofArray = typeofArray;
|
|
260
|
+
function instanceofArray(arr, strict = false) {
|
|
261
|
+
let constructor = undefined;
|
|
262
|
+
if (!(arr === null || arr === void 0 ? void 0 : arr.length)) {
|
|
263
|
+
return constructor;
|
|
109
264
|
}
|
|
110
|
-
|
|
111
|
-
|
|
265
|
+
try {
|
|
266
|
+
constructor = arr[0].constructor;
|
|
267
|
+
if (strict) {
|
|
268
|
+
for (const item of arr) {
|
|
269
|
+
if (item.constructor !== constructor) {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
112
274
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return Object.keys(instance).reduce((obj, key) => {
|
|
116
|
-
obj[key] = cloneDeep ? _.cloneDeep(values[key]) : values[key];
|
|
117
|
-
return obj;
|
|
118
|
-
}, instance);
|
|
275
|
+
catch (e) {
|
|
276
|
+
return undefined;
|
|
119
277
|
}
|
|
278
|
+
return constructor;
|
|
120
279
|
}
|
|
121
|
-
exports.
|
|
280
|
+
exports.instanceofArray = instanceofArray;
|
|
122
281
|
//# 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,
|
|
1
|
+
{"version":3,"file":"input.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/input.helper.ts"],"names":[],"mappings":";;;AAAA,2CAA4E;AAC5E,yDAAoD;AACpD,qDAA2C;AAC3C,4BAA4B;AAC5B,6EAAqE;AACrE,kDAA8C;AAE9C,2CAAqD;AAMrD,MAAqB,WAAW;IAIvB,MAAM,CAAC,KAAK,CAAC,KAAK,CACvB,KAAU,EACV,IAAwD,EACxD,OAA8F;QAE9F,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;IAGM,M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AAQ,CAAC,CAAC;AACf,CAAC;AAPD,4BAOC;AAKD,SAAgB,WAAW,CAAC,GAAU,EAAE,MAAM,GAAG,KAAK;IACpD,IAAI,IAAI,GAAW,SAAS,CAAC;IAC7B,IAAI,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,CAAA,EAAE;QAChB,OAAO,IAAI,CAAC;KACb;IACD,IAAI,GAAG,OAAO,GAAG,CAAC,CAAC,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,CAA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,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAGtC,OAAO,MAAM,CAAC;AAChB,CAAC;AA9BD,kBA8BC;AAKD,SAAgB,IAAI,CAClB,IAA6E,EAC7E,WAAsC,EACtC,SAAS,GAAG,IAAI;IAGhB,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QACrC,OAAO,SAAS,CAAC;KAClB;IAGD,IAAI,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>;
|