@lenne.tech/nest-server 9.0.8 → 9.0.9
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.d.ts +0 -1
- package/dist/core/common/args/pagination.args.js +1 -15
- package/dist/core/common/args/pagination.args.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.d.ts +54 -0
- package/dist/core/common/services/crud.service.js +78 -0
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/core/common/args/pagination.args.ts +1 -19
- package/src/core/common/helpers/service.helper.ts +1 -1
- package/src/core/common/services/crud.service.ts +216 -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.9",
|
|
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",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"@nestjs/passport": "9.0.0",
|
|
69
69
|
"@nestjs/platform-express": "9.1.4",
|
|
70
70
|
"@nestjs/schedule": "2.1.0",
|
|
71
|
-
"apollo-server-core": "3.10.
|
|
72
|
-
"apollo-server-express": "3.10.
|
|
73
|
-
"bcrypt": "5.0
|
|
71
|
+
"apollo-server-core": "3.10.3",
|
|
72
|
+
"apollo-server-express": "3.10.3",
|
|
73
|
+
"bcrypt": "5.1.0",
|
|
74
74
|
"class-transformer": "0.5.1",
|
|
75
75
|
"class-validator": "0.13.2",
|
|
76
76
|
"ejs": "3.1.8",
|
|
@@ -99,17 +99,17 @@
|
|
|
99
99
|
"@nestjs/testing": "9.1.4",
|
|
100
100
|
"@types/cron": "2.0.0",
|
|
101
101
|
"@types/ejs": "3.1.1",
|
|
102
|
-
"@types/jest": "29.1.
|
|
102
|
+
"@types/jest": "29.1.2",
|
|
103
103
|
"@types/lodash": "4.14.186",
|
|
104
104
|
"@types/multer": "1.4.7",
|
|
105
|
-
"@types/node": "18.8.
|
|
105
|
+
"@types/node": "18.8.3",
|
|
106
106
|
"@types/nodemailer": "6.4.6",
|
|
107
107
|
"@types/passport": "1.0.11",
|
|
108
108
|
"@types/supertest": "2.0.12",
|
|
109
109
|
"@typescript-eslint/eslint-plugin": "5.39.0",
|
|
110
110
|
"@typescript-eslint/parser": "5.39.0",
|
|
111
111
|
"coffeescript": "2.7.0",
|
|
112
|
-
"eslint": "8.
|
|
112
|
+
"eslint": "8.25.0",
|
|
113
113
|
"eslint-config-prettier": "8.5.0",
|
|
114
114
|
"find-file-up": "2.0.1",
|
|
115
115
|
"grunt": "1.5.3",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IsOptional, Max } from 'class-validator';
|
|
2
1
|
import { ArgsType, Field, Int } from '@nestjs/graphql';
|
|
2
|
+
import { IsOptional } from 'class-validator';
|
|
3
3
|
import { maps } from '../helpers/model.helper';
|
|
4
4
|
import { CoreInput } from '../inputs/core-input.input';
|
|
5
5
|
import { SortInput } from '../inputs/sort.input';
|
|
@@ -12,10 +12,8 @@ export class PaginationArgs extends CoreInput {
|
|
|
12
12
|
@Field((type) => Int, {
|
|
13
13
|
description: 'Limit specifies the maximum number of elements found that are to be returned',
|
|
14
14
|
nullable: true,
|
|
15
|
-
defaultValue: 25,
|
|
16
15
|
})
|
|
17
16
|
@IsOptional()
|
|
18
|
-
@Max(100)
|
|
19
17
|
limit?: number = undefined;
|
|
20
18
|
|
|
21
19
|
/**
|
|
@@ -24,7 +22,6 @@ export class PaginationArgs extends CoreInput {
|
|
|
24
22
|
@Field((type) => Int, {
|
|
25
23
|
description: 'Alias for skip',
|
|
26
24
|
nullable: true,
|
|
27
|
-
defaultValue: 0,
|
|
28
25
|
})
|
|
29
26
|
@IsOptional()
|
|
30
27
|
offset?: number = undefined;
|
|
@@ -35,7 +32,6 @@ export class PaginationArgs extends CoreInput {
|
|
|
35
32
|
@Field((type) => Int, {
|
|
36
33
|
description: 'Skip specifies how many found elements should be skipped on return',
|
|
37
34
|
nullable: true,
|
|
38
|
-
defaultValue: undefined,
|
|
39
35
|
})
|
|
40
36
|
@IsOptional()
|
|
41
37
|
skip?: number = undefined;
|
|
@@ -56,28 +52,14 @@ export class PaginationArgs extends CoreInput {
|
|
|
56
52
|
@Field((type) => Int, {
|
|
57
53
|
description: 'Alias for limit',
|
|
58
54
|
nullable: true,
|
|
59
|
-
defaultValue: 25,
|
|
60
55
|
})
|
|
61
56
|
@IsOptional()
|
|
62
|
-
@Max(100)
|
|
63
57
|
take?: number = undefined;
|
|
64
58
|
|
|
65
59
|
// ===================================================================================================================
|
|
66
60
|
// Methods
|
|
67
61
|
// ===================================================================================================================
|
|
68
62
|
|
|
69
|
-
/**
|
|
70
|
-
* Initialize instance with default values instead of undefined
|
|
71
|
-
*/
|
|
72
|
-
init(): this {
|
|
73
|
-
super.init();
|
|
74
|
-
this.limit = this.limit === undefined ? 25 : this.limit;
|
|
75
|
-
this.offset = this.offset === undefined ? 0 : this.offset;
|
|
76
|
-
this.skip = this.skip === undefined ? 0 : this.skip;
|
|
77
|
-
this.take = this.take === undefined ? 0 : this.take;
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
63
|
/**
|
|
82
64
|
* Mapping for Subtypes
|
|
83
65
|
*/
|
|
@@ -97,7 +97,7 @@ export async function prepareInput<T = any>(
|
|
|
97
97
|
if (Array.isArray(input)) {
|
|
98
98
|
const processedArray = config.getNewArray ? ([] as T & any[]) : input;
|
|
99
99
|
for (let i = 0; i <= input.length - 1; i++) {
|
|
100
|
-
processedArray[i] = await
|
|
100
|
+
processedArray[i] = await prepareInput(input[i], currentUser, options);
|
|
101
101
|
if (processedArray[i] === undefined && config.removeUndefined) {
|
|
102
102
|
processedArray.splice(i, 1);
|
|
103
103
|
}
|
|
@@ -24,6 +24,24 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Create item without checks or restrictions
|
|
29
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
30
|
+
*/
|
|
31
|
+
async createForce(input: any, serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
32
|
+
serviceOptions = merge(serviceOptions, { force: true });
|
|
33
|
+
return this.create(input, serviceOptions);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create item without checks, restrictions or preparations
|
|
38
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
39
|
+
*/
|
|
40
|
+
async createRaw(input: any, serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
41
|
+
serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
|
|
42
|
+
return this.createForce(input, serviceOptions);
|
|
43
|
+
}
|
|
44
|
+
|
|
27
45
|
/**
|
|
28
46
|
* Get item by ID
|
|
29
47
|
*/
|
|
@@ -35,6 +53,24 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
35
53
|
return this.process(async () => dbObject, { dbObject, serviceOptions });
|
|
36
54
|
}
|
|
37
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Get item by ID without checks or restrictions
|
|
58
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
59
|
+
*/
|
|
60
|
+
async getForce(id: string, serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
61
|
+
serviceOptions = merge(serviceOptions, { force: true });
|
|
62
|
+
return this.get(id, serviceOptions);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get item by ID without checks, restrictions or preparations
|
|
67
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
68
|
+
*/
|
|
69
|
+
async getRaw(id: string, serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
70
|
+
serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
|
|
71
|
+
return this.getForce(id, serviceOptions);
|
|
72
|
+
}
|
|
73
|
+
|
|
38
74
|
/**
|
|
39
75
|
* Get items via filter
|
|
40
76
|
*/
|
|
@@ -42,6 +78,12 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
42
78
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
43
79
|
serviceOptions?: ServiceOptions
|
|
44
80
|
): Promise<T[]> {
|
|
81
|
+
// If filter is not instance of FilterArgs a simple form with filterQuery and queryOptions is set
|
|
82
|
+
// and should not be processed as FilterArgs
|
|
83
|
+
if (!(filter instanceof FilterArgs) && serviceOptions?.inputType === FilterArgs) {
|
|
84
|
+
serviceOptions = Object.assign({ prepareInput: null }, serviceOptions, { inputType: null });
|
|
85
|
+
}
|
|
86
|
+
|
|
45
87
|
return this.process(
|
|
46
88
|
async (data) => {
|
|
47
89
|
// Return only a certain number of random samples
|
|
@@ -64,6 +106,30 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
64
106
|
);
|
|
65
107
|
}
|
|
66
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Get items via filter without checks or restrictions
|
|
111
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
112
|
+
*/
|
|
113
|
+
async findForce(
|
|
114
|
+
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
115
|
+
serviceOptions: ServiceOptions = {}
|
|
116
|
+
): Promise<T[]> {
|
|
117
|
+
serviceOptions = merge(serviceOptions, { force: true });
|
|
118
|
+
return this.find(filter, serviceOptions);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get items via filter without checks, restrictions or preparations
|
|
123
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
124
|
+
*/
|
|
125
|
+
async findRaw(
|
|
126
|
+
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
127
|
+
serviceOptions: ServiceOptions = {}
|
|
128
|
+
): Promise<T[]> {
|
|
129
|
+
serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
|
|
130
|
+
return this.findForce(filter, serviceOptions);
|
|
131
|
+
}
|
|
132
|
+
|
|
67
133
|
/**
|
|
68
134
|
* Get items and total count via filter
|
|
69
135
|
*/
|
|
@@ -71,6 +137,12 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
71
137
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
72
138
|
serviceOptions?: ServiceOptions
|
|
73
139
|
): Promise<{ items: T[]; totalCount: number }> {
|
|
140
|
+
// If filter is not instance of FilterArgs a simple form with filterQuery and queryOptions is set
|
|
141
|
+
// and should not be processed as FilterArgs
|
|
142
|
+
if (!(filter instanceof FilterArgs) && serviceOptions?.inputType === FilterArgs) {
|
|
143
|
+
serviceOptions = Object.assign({ prepareInput: null }, serviceOptions, { inputType: null });
|
|
144
|
+
}
|
|
145
|
+
|
|
74
146
|
return this.process(
|
|
75
147
|
async (data) => {
|
|
76
148
|
// Prepare filter query
|
|
@@ -134,6 +206,30 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
134
206
|
);
|
|
135
207
|
}
|
|
136
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Get items and total count via filter without checks or restrictions
|
|
211
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
212
|
+
*/
|
|
213
|
+
async findAndCountForce(
|
|
214
|
+
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
215
|
+
serviceOptions: ServiceOptions = {}
|
|
216
|
+
): Promise<{ items: T[]; totalCount: number }> {
|
|
217
|
+
serviceOptions = merge(serviceOptions, { force: true });
|
|
218
|
+
return this.findAndCount(filter, serviceOptions);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Get items and total count via filter without checks, restrictions or preparations
|
|
223
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
224
|
+
*/
|
|
225
|
+
async findAndCountRaw(
|
|
226
|
+
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
227
|
+
serviceOptions: ServiceOptions = {}
|
|
228
|
+
): Promise<{ items: T[]; totalCount: number }> {
|
|
229
|
+
serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
|
|
230
|
+
return this.findAndCountForce(filter, serviceOptions);
|
|
231
|
+
}
|
|
232
|
+
|
|
137
233
|
/**
|
|
138
234
|
* Find and update
|
|
139
235
|
*/
|
|
@@ -162,6 +258,30 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
162
258
|
return await Promise.all(promises);
|
|
163
259
|
}
|
|
164
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Find and update without checks or restrictions
|
|
263
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
264
|
+
*/
|
|
265
|
+
async findAndUpdateForce(
|
|
266
|
+
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
267
|
+
serviceOptions: ServiceOptions = {}
|
|
268
|
+
): Promise<T[]> {
|
|
269
|
+
serviceOptions = merge(serviceOptions, { force: true });
|
|
270
|
+
return this.findAndUpdate(filter, serviceOptions);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Find and update without checks, restrictions or preparations
|
|
275
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
276
|
+
*/
|
|
277
|
+
async findAndUpdateRaw(
|
|
278
|
+
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
279
|
+
serviceOptions: ServiceOptions = {}
|
|
280
|
+
): Promise<T[]> {
|
|
281
|
+
serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
|
|
282
|
+
return this.findAndUpdateForce(filter, serviceOptions);
|
|
283
|
+
}
|
|
284
|
+
|
|
165
285
|
/**
|
|
166
286
|
* CRUD alias for get
|
|
167
287
|
*/
|
|
@@ -189,6 +309,66 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
189
309
|
}
|
|
190
310
|
}
|
|
191
311
|
|
|
312
|
+
/**
|
|
313
|
+
* CRUD alias for getForce
|
|
314
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
315
|
+
*/
|
|
316
|
+
async readForce(id: string, serviceOptions?: ServiceOptions): Promise<T>;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* CRUD alias for findForce
|
|
320
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
321
|
+
*/
|
|
322
|
+
async readForce(
|
|
323
|
+
filter: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions },
|
|
324
|
+
serviceOptions?: ServiceOptions
|
|
325
|
+
): Promise<T[]>;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* CRUD alias for getForce or findForce
|
|
329
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
330
|
+
*/
|
|
331
|
+
async readForce(
|
|
332
|
+
input: string | FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions },
|
|
333
|
+
serviceOptions?: ServiceOptions
|
|
334
|
+
): Promise<T | T[]> {
|
|
335
|
+
if (typeof input === 'string') {
|
|
336
|
+
return this.getForce(input, serviceOptions);
|
|
337
|
+
} else {
|
|
338
|
+
return this.findForce(input, serviceOptions);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* CRUD alias for getRaw
|
|
344
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
345
|
+
*/
|
|
346
|
+
async readRaw(id: string, serviceOptions?: ServiceOptions): Promise<T>;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* CRUD alias for findRaw
|
|
350
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
351
|
+
*/
|
|
352
|
+
async readRaw(
|
|
353
|
+
filter: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions },
|
|
354
|
+
serviceOptions?: ServiceOptions
|
|
355
|
+
): Promise<T[]>;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* CRUD alias for getRaw or findRaw
|
|
359
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
360
|
+
*/
|
|
361
|
+
async readRaw(
|
|
362
|
+
input: string | FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions },
|
|
363
|
+
serviceOptions?: ServiceOptions
|
|
364
|
+
): Promise<T | T[]> {
|
|
365
|
+
if (typeof input === 'string') {
|
|
366
|
+
return this.getRaw(input, serviceOptions);
|
|
367
|
+
} else {
|
|
368
|
+
return this.findRaw(input, serviceOptions);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
192
372
|
/**
|
|
193
373
|
* Update item via ID
|
|
194
374
|
*/
|
|
@@ -206,6 +386,24 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
206
386
|
);
|
|
207
387
|
}
|
|
208
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Update item via ID without checks or restrictions
|
|
391
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
392
|
+
*/
|
|
393
|
+
async updateForce(id: string, input: any, serviceOptions?: ServiceOptions): Promise<T> {
|
|
394
|
+
serviceOptions = merge(serviceOptions, { force: true });
|
|
395
|
+
return this.update(id, input, serviceOptions);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Update item via ID without checks, restrictions or preparations
|
|
400
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
401
|
+
*/
|
|
402
|
+
async updateRaw(id: string, input: any, serviceOptions?: ServiceOptions): Promise<T> {
|
|
403
|
+
serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
|
|
404
|
+
return this.updateForce(id, input, serviceOptions);
|
|
405
|
+
}
|
|
406
|
+
|
|
209
407
|
/**
|
|
210
408
|
* Delete item via ID
|
|
211
409
|
*/
|
|
@@ -222,4 +420,22 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
|
|
|
222
420
|
{ dbObject, serviceOptions }
|
|
223
421
|
);
|
|
224
422
|
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Delete item via ID without checks or restrictions
|
|
426
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
427
|
+
*/
|
|
428
|
+
async deleteForce(id: string, serviceOptions?: ServiceOptions): Promise<T> {
|
|
429
|
+
serviceOptions = merge(serviceOptions, { force: true });
|
|
430
|
+
return this.delete(id, serviceOptions);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Delete item via ID without checks, restrictions or preparations
|
|
435
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
436
|
+
*/
|
|
437
|
+
async deleteRaw(id: string, serviceOptions?: ServiceOptions): Promise<T> {
|
|
438
|
+
serviceOptions = merge(serviceOptions, { prepareInput: null, prepareOutput: null });
|
|
439
|
+
return this.deleteForce(id, serviceOptions);
|
|
440
|
+
}
|
|
225
441
|
}
|