@lenne.tech/nest-server 10.2.0 → 10.2.1
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/db.helper.js +16 -4
- package/dist/core/common/helpers/db.helper.js.map +1 -1
- package/dist/core/common/helpers/input.helper.js +1 -1
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/helpers/service.helper.js +2 -2
- package/dist/core/common/helpers/service.helper.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 +2 -10
- package/dist/core/common/services/crud.service.js +7 -14
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/core/modules/auth/core-auth.controller.js +1 -1
- package/dist/core/modules/auth/core-auth.controller.js.map +1 -1
- package/dist/core/modules/auth/core-auth.resolver.js +1 -1
- package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/common/helpers/db.helper.ts +16 -4
- package/src/core/common/helpers/input.helper.ts +1 -1
- package/src/core/common/helpers/service.helper.ts +2 -2
- package/src/core/common/pipes/map-and-validate.pipe.ts +1 -1
- package/src/core/common/services/crud.service.ts +12 -31
- package/src/core/modules/auth/core-auth.controller.ts +1 -1
- package/src/core/modules/auth/core-auth.resolver.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "10.2.
|
|
3
|
+
"version": "10.2.1",
|
|
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",
|
|
@@ -505,8 +505,13 @@ export async function popAndMap<T extends CoreModel>(
|
|
|
505
505
|
|
|
506
506
|
// Map result
|
|
507
507
|
if (Array.isArray(result)) {
|
|
508
|
-
result = result.map(item =>
|
|
509
|
-
|
|
508
|
+
result = result.map((item) => {
|
|
509
|
+
if (item && typeof item === 'object') {
|
|
510
|
+
return (modelClass as any).map(item);
|
|
511
|
+
}
|
|
512
|
+
return item;
|
|
513
|
+
});
|
|
514
|
+
} else if (result && typeof result === 'object') {
|
|
510
515
|
result = (modelClass as any).map(result);
|
|
511
516
|
}
|
|
512
517
|
|
|
@@ -514,12 +519,19 @@ export async function popAndMap<T extends CoreModel>(
|
|
|
514
519
|
} else {
|
|
515
520
|
if (Array.isArray(queryOrDocument)) {
|
|
516
521
|
await setPopulates(queryOrDocument, populateOptions, mongooseModel, { ignoreSelections });
|
|
517
|
-
result = queryOrDocument.map(item =>
|
|
522
|
+
result = queryOrDocument.map((item) => {
|
|
523
|
+
if (item && typeof item === 'object') {
|
|
524
|
+
return (modelClass as any).map(item);
|
|
525
|
+
}
|
|
526
|
+
return item;
|
|
527
|
+
});
|
|
518
528
|
|
|
519
529
|
// Process document
|
|
520
530
|
} else {
|
|
521
531
|
await setPopulates(queryOrDocument, populateOptions, mongooseModel, { ignoreSelections });
|
|
522
|
-
|
|
532
|
+
if (queryOrDocument && typeof queryOrDocument === 'object') {
|
|
533
|
+
result = (modelClass as any).map(queryOrDocument);
|
|
534
|
+
}
|
|
523
535
|
}
|
|
524
536
|
}
|
|
525
537
|
|
|
@@ -92,7 +92,7 @@ export async function prepareInput<T = any>(
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
// Check input
|
|
95
|
-
if (typeof input !== 'object') {
|
|
95
|
+
if (!input || typeof input !== 'object') {
|
|
96
96
|
return input;
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -206,7 +206,7 @@ export async function prepareOutput<T = { [key: string]: any; map: (...args: any
|
|
|
206
206
|
};
|
|
207
207
|
|
|
208
208
|
// Check output
|
|
209
|
-
if (typeof output !== 'object') {
|
|
209
|
+
if (!output || typeof output !== 'object') {
|
|
210
210
|
return output;
|
|
211
211
|
}
|
|
212
212
|
|
|
@@ -8,7 +8,7 @@ export class MapAndValidatePipe implements PipeTransform {
|
|
|
8
8
|
async transform(value: any, metadata: ArgumentMetadata) {
|
|
9
9
|
const { metatype } = metadata;
|
|
10
10
|
|
|
11
|
-
if (typeof value !== 'object' || !metatype || isBasicType(metatype)) {
|
|
11
|
+
if (!value || typeof value !== 'object' || !metatype || isBasicType(metatype)) {
|
|
12
12
|
return value;
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { NotFoundException } from '@nestjs/common';
|
|
2
|
-
import { Document, FilterQuery,
|
|
2
|
+
import { Document, FilterQuery, PipelineStage, Query, QueryOptions } from 'mongoose';
|
|
3
3
|
import { FilterArgs } from '../args/filter.args';
|
|
4
|
-
import { getStringIds
|
|
4
|
+
import { getStringIds } from '../helpers/db.helper';
|
|
5
5
|
import { convertFilterArgsToQuery } from '../helpers/filter.helper';
|
|
6
6
|
import { mergePlain, prepareServiceOptionsForCreate } from '../helpers/input.helper';
|
|
7
7
|
import { ServiceOptions } from '../interfaces/service-options.interface';
|
|
8
8
|
import { CoreModel } from '../models/core-model.model';
|
|
9
|
-
import { ArrayElement } from '../types/array-element.type';
|
|
10
|
-
import { FieldSelection } from '../types/field-selection.type';
|
|
11
9
|
import { PlainObject } from '../types/plain-object.type';
|
|
12
10
|
import { ConfigService } from './config.service';
|
|
13
11
|
import { ModuleService } from './module.service';
|
|
@@ -478,38 +476,21 @@ export abstract class CrudService<
|
|
|
478
476
|
}
|
|
479
477
|
|
|
480
478
|
/**
|
|
481
|
-
*
|
|
479
|
+
* Execute, populate and map Mongoose query or document(s) with serviceOptions
|
|
482
480
|
* Generic T is the type of the returned object(s)
|
|
483
481
|
*
|
|
484
482
|
* @example const user = await this.populateAndProcessQuery<User>(User.findById(id), serviceOptions);
|
|
485
|
-
* @example const users = await this.populateAndProcessQuery<User[]>(User.find({name: {'$regex': 'ma'}}), serviceOptions);
|
|
483
|
+
* @example const users = await this.populateAndProcessQuery<User[]>(User.find({name: {'$regex': 'ma'}}), {...serviceOptions, populate:['contacts'], force: true});
|
|
486
484
|
*/
|
|
487
|
-
async
|
|
485
|
+
async processQueryOrDocument<T extends CoreModel | CoreModel[] = CoreModel>(
|
|
488
486
|
queryOrDocument: Query<unknown, unknown> | Document | Document[],
|
|
489
|
-
|
|
490
|
-
fieldSelection?: FieldSelection;
|
|
491
|
-
ignoreSelections?: boolean;
|
|
492
|
-
modelClass?: new (...args: any[]) => ArrayElement<T>;
|
|
493
|
-
populate?: FieldSelection;
|
|
494
|
-
mongooseModel?: MongooseModel<any>;
|
|
495
|
-
},
|
|
487
|
+
serviceOptions?: ServiceOptions,
|
|
496
488
|
): Promise<T> {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if (config.fieldSelection || config.populate) {
|
|
504
|
-
result = (await popAndMap<ArrayElement<T>>(
|
|
505
|
-
queryOrDocument,
|
|
506
|
-
config.populate || config.fieldSelection,
|
|
507
|
-
config.modelClass as new (...args: any[]) => ArrayElement<T>,
|
|
508
|
-
config.mongooseModel)
|
|
509
|
-
) as T;
|
|
510
|
-
} else if (queryOrDocument instanceof Query) {
|
|
511
|
-
result = (await queryOrDocument.exec()) as T;
|
|
512
|
-
}
|
|
513
|
-
return result;
|
|
489
|
+
return this.process(() => {
|
|
490
|
+
if (queryOrDocument instanceof Query) {
|
|
491
|
+
return queryOrDocument.exec();
|
|
492
|
+
}
|
|
493
|
+
return queryOrDocument;
|
|
494
|
+
}, { serviceOptions });
|
|
514
495
|
}
|
|
515
496
|
}
|
|
@@ -77,7 +77,7 @@ export class CoreAuthController {
|
|
|
77
77
|
// Check if cookie handling is activated
|
|
78
78
|
if (this.configService.getFastButReadOnly('cookies')) {
|
|
79
79
|
// Set cookies
|
|
80
|
-
if (typeof result !== 'object') {
|
|
80
|
+
if (!result || typeof result !== 'object') {
|
|
81
81
|
res.cookie('token', '', { httpOnly: true });
|
|
82
82
|
res.cookie('refreshToken', '', { httpOnly: true });
|
|
83
83
|
return result;
|
|
@@ -96,7 +96,7 @@ export class CoreAuthResolver {
|
|
|
96
96
|
// Check if cookie handling is activated
|
|
97
97
|
if (this.configService.getFastButReadOnly('cookies')) {
|
|
98
98
|
// Set cookies
|
|
99
|
-
if (typeof result !== 'object') {
|
|
99
|
+
if (!result || typeof result !== 'object') {
|
|
100
100
|
ctx.res.cookie('token', '', { httpOnly: true });
|
|
101
101
|
ctx.res.cookie('refreshToken', '', { httpOnly: true });
|
|
102
102
|
return result;
|