@lenne.tech/nest-server 10.2.5 → 10.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "10.2.5",
3
+ "version": "10.2.6",
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",
@@ -12,7 +12,7 @@ import { processDeep } from '../helpers/input.helper';
12
12
  export class CheckSecurityInterceptor implements NestInterceptor {
13
13
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
14
14
  // Get current user
15
- const user = getContextData(context)?.currentUser;
15
+ const user = getContextData(context)?.currentUser || null;
16
16
 
17
17
  // Set force mode for sign in and sign up
18
18
  let force = false;
@@ -311,6 +311,69 @@ export abstract class CrudService<
311
311
  return this.findAndUpdateForce(filter, update, serviceOptions);
312
312
  }
313
313
 
314
+ /**
315
+ * Find one item via filter
316
+ */
317
+ async findOne(
318
+ filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions },
319
+ serviceOptions?: ServiceOptions,
320
+ ): Promise<Model> {
321
+ // If filter is not instance of FilterArgs a simple form with filterQuery and queryOptions is set
322
+ // and should not be processed as FilterArgs
323
+ if (!(filter instanceof FilterArgs) && serviceOptions?.inputType === FilterArgs) {
324
+ serviceOptions = Object.assign({ prepareInput: null }, serviceOptions, { inputType: null });
325
+ }
326
+
327
+ return this.process(
328
+ async (data) => {
329
+
330
+ // Prepare filter query
331
+ const filterQuery = { filterQuery: data?.input?.filterQuery, queryOptions: data?.input?.queryOptions };
332
+ if (data?.input instanceof FilterArgs) {
333
+ const converted = convertFilterArgsToQuery(data.input);
334
+ filterQuery.filterQuery = converted[0];
335
+ filterQuery.queryOptions = converted[1];
336
+ }
337
+
338
+ // Find in DB
339
+ let find = this.mainDbModel.findOne(filterQuery.filterQuery, null, filterQuery.queryOptions);
340
+ const collation = serviceOptions?.collation || ConfigService.get('mongoose.collation');
341
+ if (collation) {
342
+ find = find.collation(collation);
343
+ }
344
+ return find.exec();
345
+ },
346
+ { input: filter, serviceOptions },
347
+ );
348
+ }
349
+
350
+ /**
351
+ * Find one item via filter without checks or restrictions
352
+ * Warning: Disables the handling of rights and restrictions!
353
+ */
354
+ async findOneForce(
355
+ filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
356
+ serviceOptions: ServiceOptions = {},
357
+ ): Promise<Model> {
358
+ serviceOptions = serviceOptions || {};
359
+ serviceOptions.force = true;
360
+ return this.findOne(filter, serviceOptions);
361
+ }
362
+
363
+ /**
364
+ * Find one item via filter without checks, restrictions or preparations
365
+ * Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
366
+ */
367
+ async findOneRaw(
368
+ filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
369
+ serviceOptions: ServiceOptions = {},
370
+ ): Promise<Model> {
371
+ serviceOptions = serviceOptions || {};
372
+ serviceOptions.prepareInput = null;
373
+ serviceOptions.prepareOutput = null;
374
+ return this.findOneForce(filter, serviceOptions);
375
+ }
376
+
314
377
  /**
315
378
  * CRUD alias for get
316
379
  */