@lenne.tech/nest-server 9.0.27 → 9.0.29
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/input.helper.d.ts +1 -0
- package/dist/core/common/helpers/input.helper.js +14 -1
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/helpers/service.helper.js +1 -1
- package/dist/core/common/helpers/service.helper.js.map +1 -1
- package/dist/core/common/services/crud.service.js +36 -16
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/core/modules/auth/services/core-auth.service.js +2 -2
- package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
- package/dist/core/modules/user/core-user.service.js +1 -2
- package/dist/core/modules/user/core-user.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/common/helpers/input.helper.ts +16 -0
- package/src/core/common/helpers/service.helper.ts +1 -1
- package/src/core/common/services/crud.service.ts +37 -17
- package/src/core/modules/auth/services/core-auth.service.ts +2 -2
- package/src/core/modules/user/core-user.service.ts +2 -3
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.29",
|
|
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",
|
|
@@ -702,3 +702,19 @@ export function processDeep(
|
|
|
702
702
|
// Process others
|
|
703
703
|
return func(data);
|
|
704
704
|
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Helper to avoid very slow merge of serviceOptions
|
|
708
|
+
*/
|
|
709
|
+
export function prepareServiceOptionsForCreate(serviceOptions: any) {
|
|
710
|
+
if (!serviceOptions) {
|
|
711
|
+
serviceOptions = {};
|
|
712
|
+
}
|
|
713
|
+
if (!serviceOptions.prepareInput) {
|
|
714
|
+
serviceOptions.prepareInput = {};
|
|
715
|
+
}
|
|
716
|
+
if (serviceOptions.prepareInput.create === undefined) {
|
|
717
|
+
serviceOptions.prepareInput.create;
|
|
718
|
+
}
|
|
719
|
+
return serviceOptions;
|
|
720
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { NotFoundException } from '@nestjs/common';
|
|
2
2
|
import { FilterQuery, PipelineStage, QueryOptions } from 'mongoose';
|
|
3
3
|
import { FilterArgs } from '../args/filter.args';
|
|
4
|
-
import { merge } from '../helpers/config.helper';
|
|
5
4
|
import { getStringIds } from '../helpers/db.helper';
|
|
6
5
|
import { convertFilterArgsToQuery } from '../helpers/filter.helper';
|
|
7
|
-
import { mergePlain } from '../helpers/input.helper';
|
|
6
|
+
import { mergePlain, prepareServiceOptionsForCreate } from '../helpers/input.helper';
|
|
8
7
|
import { ServiceOptions } from '../interfaces/service-options.interface';
|
|
9
8
|
import { CoreModel } from '../models/core-model.model';
|
|
10
9
|
import { ConfigService } from './config.service';
|
|
@@ -15,7 +14,7 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
15
14
|
* Create item
|
|
16
15
|
*/
|
|
17
16
|
async create(input: any, serviceOptions?: ServiceOptions): Promise<T> {
|
|
18
|
-
serviceOptions =
|
|
17
|
+
serviceOptions = prepareServiceOptionsForCreate(serviceOptions);
|
|
19
18
|
return this.process(
|
|
20
19
|
async (data) => {
|
|
21
20
|
const currentUserId = serviceOptions?.currentUser?.id;
|
|
@@ -30,7 +29,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
30
29
|
* Warning: Disables the handling of rights and restrictions!
|
|
31
30
|
*/
|
|
32
31
|
async createForce(input: any, serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
33
|
-
serviceOptions =
|
|
32
|
+
serviceOptions = serviceOptions || {};
|
|
33
|
+
serviceOptions.force = true;
|
|
34
34
|
return this.create(input, serviceOptions);
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -39,7 +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
|
-
serviceOptions =
|
|
42
|
+
serviceOptions = serviceOptions || {};
|
|
43
|
+
serviceOptions.prepareInput = null;
|
|
44
|
+
serviceOptions.prepareOutput = null;
|
|
43
45
|
return this.createForce(input, serviceOptions);
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -59,7 +61,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
59
61
|
* Warning: Disables the handling of rights and restrictions!
|
|
60
62
|
*/
|
|
61
63
|
async getForce(id: string, serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
62
|
-
serviceOptions =
|
|
64
|
+
serviceOptions = serviceOptions || {};
|
|
65
|
+
serviceOptions.force = true;
|
|
63
66
|
return this.get(id, serviceOptions);
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -68,7 +71,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
68
71
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
69
72
|
*/
|
|
70
73
|
async getRaw(id: string, serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
71
|
-
serviceOptions =
|
|
74
|
+
serviceOptions = serviceOptions || {};
|
|
75
|
+
serviceOptions.prepareInput = null;
|
|
76
|
+
serviceOptions.prepareOutput = null;
|
|
72
77
|
return this.getForce(id, serviceOptions);
|
|
73
78
|
}
|
|
74
79
|
|
|
@@ -120,7 +125,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
120
125
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
121
126
|
serviceOptions: ServiceOptions = {}
|
|
122
127
|
): Promise<T[]> {
|
|
123
|
-
serviceOptions =
|
|
128
|
+
serviceOptions = serviceOptions || {};
|
|
129
|
+
serviceOptions.force = true;
|
|
124
130
|
return this.find(filter, serviceOptions);
|
|
125
131
|
}
|
|
126
132
|
|
|
@@ -132,7 +138,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
132
138
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
133
139
|
serviceOptions: ServiceOptions = {}
|
|
134
140
|
): Promise<T[]> {
|
|
135
|
-
serviceOptions =
|
|
141
|
+
serviceOptions = serviceOptions || {};
|
|
142
|
+
serviceOptions.prepareInput = null;
|
|
143
|
+
serviceOptions.prepareOutput = null;
|
|
136
144
|
return this.findForce(filter, serviceOptions);
|
|
137
145
|
}
|
|
138
146
|
|
|
@@ -222,7 +230,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
222
230
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
223
231
|
serviceOptions: ServiceOptions = {}
|
|
224
232
|
): Promise<{ items: T[]; totalCount: number }> {
|
|
225
|
-
serviceOptions =
|
|
233
|
+
serviceOptions = serviceOptions || {};
|
|
234
|
+
serviceOptions.force = true;
|
|
226
235
|
return this.findAndCount(filter, serviceOptions);
|
|
227
236
|
}
|
|
228
237
|
|
|
@@ -234,7 +243,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
234
243
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
235
244
|
serviceOptions: ServiceOptions = {}
|
|
236
245
|
): Promise<{ items: T[]; totalCount: number }> {
|
|
237
|
-
serviceOptions =
|
|
246
|
+
serviceOptions = serviceOptions || {};
|
|
247
|
+
serviceOptions.prepareInput = null;
|
|
248
|
+
serviceOptions.prepareOutput = null;
|
|
238
249
|
return this.findAndCountForce(filter, serviceOptions);
|
|
239
250
|
}
|
|
240
251
|
|
|
@@ -274,7 +285,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
274
285
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
275
286
|
serviceOptions: ServiceOptions = {}
|
|
276
287
|
): Promise<T[]> {
|
|
277
|
-
serviceOptions =
|
|
288
|
+
serviceOptions = serviceOptions || {};
|
|
289
|
+
serviceOptions.force = true;
|
|
278
290
|
return this.findAndUpdate(filter, serviceOptions);
|
|
279
291
|
}
|
|
280
292
|
|
|
@@ -286,7 +298,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
286
298
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
287
299
|
serviceOptions: ServiceOptions = {}
|
|
288
300
|
): Promise<T[]> {
|
|
289
|
-
serviceOptions =
|
|
301
|
+
serviceOptions = serviceOptions || {};
|
|
302
|
+
serviceOptions.prepareInput = null;
|
|
303
|
+
serviceOptions.prepareOutput = null;
|
|
290
304
|
return this.findAndUpdateForce(filter, serviceOptions);
|
|
291
305
|
}
|
|
292
306
|
|
|
@@ -399,7 +413,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
399
413
|
* Warning: Disables the handling of rights and restrictions!
|
|
400
414
|
*/
|
|
401
415
|
async updateForce(id: string, input: any, serviceOptions?: ServiceOptions): Promise<T> {
|
|
402
|
-
serviceOptions =
|
|
416
|
+
serviceOptions = serviceOptions || {};
|
|
417
|
+
serviceOptions.force = true;
|
|
403
418
|
return this.update(id, input, serviceOptions);
|
|
404
419
|
}
|
|
405
420
|
|
|
@@ -408,7 +423,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
408
423
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
409
424
|
*/
|
|
410
425
|
async updateRaw(id: string, input: any, serviceOptions?: ServiceOptions): Promise<T> {
|
|
411
|
-
serviceOptions =
|
|
426
|
+
serviceOptions = serviceOptions || {};
|
|
427
|
+
serviceOptions.prepareInput = null;
|
|
428
|
+
serviceOptions.prepareOutput = null;
|
|
412
429
|
return this.updateForce(id, input, serviceOptions);
|
|
413
430
|
}
|
|
414
431
|
|
|
@@ -434,7 +451,8 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
434
451
|
* Warning: Disables the handling of rights and restrictions!
|
|
435
452
|
*/
|
|
436
453
|
async deleteForce(id: string, serviceOptions?: ServiceOptions): Promise<T> {
|
|
437
|
-
serviceOptions =
|
|
454
|
+
serviceOptions = serviceOptions || {};
|
|
455
|
+
serviceOptions.force = true;
|
|
438
456
|
return this.delete(id, serviceOptions);
|
|
439
457
|
}
|
|
440
458
|
|
|
@@ -443,7 +461,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
443
461
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
444
462
|
*/
|
|
445
463
|
async deleteRaw(id: string, serviceOptions?: ServiceOptions): Promise<T> {
|
|
446
|
-
serviceOptions =
|
|
464
|
+
serviceOptions = serviceOptions || {};
|
|
465
|
+
serviceOptions.prepareInput = null;
|
|
466
|
+
serviceOptions.prepareOutput = null;
|
|
447
467
|
return this.deleteForce(id, serviceOptions);
|
|
448
468
|
}
|
|
449
469
|
}
|
|
@@ -2,7 +2,6 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|
|
2
2
|
import { JwtService } from '@nestjs/jwt';
|
|
3
3
|
import * as bcrypt from 'bcrypt';
|
|
4
4
|
import { sha256 } from 'js-sha256';
|
|
5
|
-
import { merge } from '../../../common/helpers/config.helper';
|
|
6
5
|
import { ServiceOptions } from '../../../common/interfaces/service-options.interface';
|
|
7
6
|
import { ICoreAuthUser } from '../interfaces/core-auth-user.interface';
|
|
8
7
|
import { JwtPayload } from '../interfaces/jwt-payload.interface';
|
|
@@ -23,7 +22,8 @@ export class CoreAuthService {
|
|
|
23
22
|
password: string,
|
|
24
23
|
serviceOptions?: ServiceOptions
|
|
25
24
|
): Promise<{ token: string; user: ICoreAuthUser }> {
|
|
26
|
-
serviceOptions =
|
|
25
|
+
serviceOptions = serviceOptions || {};
|
|
26
|
+
serviceOptions.prepareOutput = null;
|
|
27
27
|
|
|
28
28
|
// Get user
|
|
29
29
|
const user = await this.userService.getViaEmail(email, serviceOptions);
|
|
@@ -3,8 +3,7 @@ import * as bcrypt from 'bcrypt';
|
|
|
3
3
|
import * as crypto from 'crypto';
|
|
4
4
|
import { sha256 } from 'js-sha256';
|
|
5
5
|
import { Document, Model } from 'mongoose';
|
|
6
|
-
import {
|
|
7
|
-
import { assignPlain } from '../../common/helpers/input.helper';
|
|
6
|
+
import { assignPlain, prepareServiceOptionsForCreate } from '../../common/helpers/input.helper';
|
|
8
7
|
import { ServiceOptions } from '../../common/interfaces/service-options.interface';
|
|
9
8
|
import { ConfigService } from '../../common/services/config.service';
|
|
10
9
|
import { CrudService } from '../../common/services/crud.service';
|
|
@@ -39,7 +38,7 @@ export abstract class CoreUserService<
|
|
|
39
38
|
* Create user
|
|
40
39
|
*/
|
|
41
40
|
override async create(input: any, serviceOptions?: ServiceOptions): Promise<TUser> {
|
|
42
|
-
serviceOptions =
|
|
41
|
+
serviceOptions = prepareServiceOptionsForCreate(serviceOptions);
|
|
43
42
|
return this.process(
|
|
44
43
|
async (data) => {
|
|
45
44
|
// Create user with verification token
|