@lenne.tech/nest-server 9.0.28 → 9.0.30
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/helpers/service.helper.js +0 -6
- package/dist/core/common/helpers/service.helper.js.map +1 -1
- package/dist/core/common/interfaces/service-options.interface.d.ts +2 -0
- package/dist/core/common/services/crud.service.js +21 -28
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/core/common/services/module.service.js +7 -0
- package/dist/core/common/services/module.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/common/helpers/service.helper.ts +0 -10
- package/src/core/common/interfaces/service-options.interface.ts +10 -0
- package/src/core/common/services/crud.service.ts +21 -28
- package/src/core/common/services/module.service.ts +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.30",
|
|
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",
|
|
@@ -171,16 +171,6 @@ export async function prepareInput<T = any>(
|
|
|
171
171
|
(input as any).password = await bcrypt.hash((input as any).password, 10);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
// Set creator
|
|
175
|
-
if (config.create && currentUser) {
|
|
176
|
-
(input as Record<string, any>).createdBy = currentUser.id;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Set updater
|
|
180
|
-
if (currentUser) {
|
|
181
|
-
(input as Record<string, any>).updatedBy = currentUser.id;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
174
|
// Return prepared input
|
|
185
175
|
return input;
|
|
186
176
|
}
|
|
@@ -20,6 +20,11 @@ export interface ServiceOptions {
|
|
|
20
20
|
// See https://www.mongodb.com/docs/manual/reference/collation/
|
|
21
21
|
collation?: CollationOptions;
|
|
22
22
|
|
|
23
|
+
// Create mode activated (see e.g. setCreateOrUpdateUserId)
|
|
24
|
+
// If falsy (default): create mode is deactivated
|
|
25
|
+
// If truly: create mode is activated
|
|
26
|
+
create?: boolean;
|
|
27
|
+
|
|
23
28
|
// Current user to set ownership, check rights and other things
|
|
24
29
|
currentUser?: {
|
|
25
30
|
[key: string]: any;
|
|
@@ -63,6 +68,11 @@ export interface ServiceOptions {
|
|
|
63
68
|
// Whether to publish action via GraphQL subscription
|
|
64
69
|
pubSub?: boolean;
|
|
65
70
|
|
|
71
|
+
// Add updateBy and/or createBy user ID into input after check
|
|
72
|
+
// If falsy: input data will not be changed
|
|
73
|
+
// If truly (default): updatedBy and/or createdBy (when create mode is activated) will be set if current user is available
|
|
74
|
+
setCreateOrUpdateUserId?: boolean;
|
|
75
|
+
|
|
66
76
|
// Roles (as string) to check
|
|
67
77
|
roles?: string | string[];
|
|
68
78
|
}
|
|
@@ -39,10 +39,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
39
39
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
40
40
|
*/
|
|
41
41
|
async createRaw(input: any, serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
42
|
+
serviceOptions = serviceOptions || {};
|
|
43
|
+
serviceOptions.prepareInput = null;
|
|
44
|
+
serviceOptions.prepareOutput = null;
|
|
46
45
|
return this.createForce(input, serviceOptions);
|
|
47
46
|
}
|
|
48
47
|
|
|
@@ -72,10 +71,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
72
71
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
73
72
|
*/
|
|
74
73
|
async getRaw(id: string, serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
74
|
+
serviceOptions = serviceOptions || {};
|
|
75
|
+
serviceOptions.prepareInput = null;
|
|
76
|
+
serviceOptions.prepareOutput = null;
|
|
79
77
|
return this.getForce(id, serviceOptions);
|
|
80
78
|
}
|
|
81
79
|
|
|
@@ -140,10 +138,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
140
138
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
141
139
|
serviceOptions: ServiceOptions = {}
|
|
142
140
|
): Promise<T[]> {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
141
|
+
serviceOptions = serviceOptions || {};
|
|
142
|
+
serviceOptions.prepareInput = null;
|
|
143
|
+
serviceOptions.prepareOutput = null;
|
|
147
144
|
return this.findForce(filter, serviceOptions);
|
|
148
145
|
}
|
|
149
146
|
|
|
@@ -246,10 +243,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
246
243
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
247
244
|
serviceOptions: ServiceOptions = {}
|
|
248
245
|
): Promise<{ items: T[]; totalCount: number }> {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
246
|
+
serviceOptions = serviceOptions || {};
|
|
247
|
+
serviceOptions.prepareInput = null;
|
|
248
|
+
serviceOptions.prepareOutput = null;
|
|
253
249
|
return this.findAndCountForce(filter, serviceOptions);
|
|
254
250
|
}
|
|
255
251
|
|
|
@@ -302,10 +298,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
302
298
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
303
299
|
serviceOptions: ServiceOptions = {}
|
|
304
300
|
): Promise<T[]> {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
301
|
+
serviceOptions = serviceOptions || {};
|
|
302
|
+
serviceOptions.prepareInput = null;
|
|
303
|
+
serviceOptions.prepareOutput = null;
|
|
309
304
|
return this.findAndUpdateForce(filter, serviceOptions);
|
|
310
305
|
}
|
|
311
306
|
|
|
@@ -428,10 +423,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
428
423
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
429
424
|
*/
|
|
430
425
|
async updateRaw(id: string, input: any, serviceOptions?: ServiceOptions): Promise<T> {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
426
|
+
serviceOptions = serviceOptions || {};
|
|
427
|
+
serviceOptions.prepareInput = null;
|
|
428
|
+
serviceOptions.prepareOutput = null;
|
|
435
429
|
return this.updateForce(id, input, serviceOptions);
|
|
436
430
|
}
|
|
437
431
|
|
|
@@ -467,10 +461,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
467
461
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
468
462
|
*/
|
|
469
463
|
async deleteRaw(id: string, serviceOptions?: ServiceOptions): Promise<T> {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
464
|
+
serviceOptions = serviceOptions || {};
|
|
465
|
+
serviceOptions.prepareInput = null;
|
|
466
|
+
serviceOptions.prepareOutput = null;
|
|
474
467
|
return this.deleteForce(id, serviceOptions);
|
|
475
468
|
}
|
|
476
469
|
}
|
|
@@ -86,6 +86,7 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
86
86
|
prepareInput: {},
|
|
87
87
|
prepareOutput: {},
|
|
88
88
|
pubSub: true,
|
|
89
|
+
setCreateOrUpdateUserId: true,
|
|
89
90
|
...options?.serviceOptions,
|
|
90
91
|
};
|
|
91
92
|
|
|
@@ -138,6 +139,16 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
138
139
|
await this.checkRights(undefined, config.currentUser as any, config);
|
|
139
140
|
}
|
|
140
141
|
|
|
142
|
+
if (config.input && config.currentUser && config.setCreateOrUpdateUserId) {
|
|
143
|
+
// Set creator
|
|
144
|
+
if (config.create) {
|
|
145
|
+
(config.input as Record<string, any>).createdBy = config.currentUser.id;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Set updater
|
|
149
|
+
(config.input as Record<string, any>).updatedBy = config.currentUser.id;
|
|
150
|
+
}
|
|
151
|
+
|
|
141
152
|
// Run service function
|
|
142
153
|
let result = await serviceFunc(config);
|
|
143
154
|
|