@lenne.tech/nest-server 9.0.13 → 9.0.14

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": "9.0.13",
3
+ "version": "9.0.14",
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",
@@ -99,15 +99,15 @@
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.2",
102
+ "@types/jest": "29.2.0",
103
103
  "@types/lodash": "4.14.186",
104
104
  "@types/multer": "1.4.7",
105
- "@types/node": "18.8.5",
105
+ "@types/node": "18.11.2",
106
106
  "@types/nodemailer": "6.4.6",
107
107
  "@types/passport": "1.0.11",
108
108
  "@types/supertest": "2.0.12",
109
- "@typescript-eslint/eslint-plugin": "5.40.0",
110
- "@typescript-eslint/parser": "5.40.0",
109
+ "@typescript-eslint/eslint-plugin": "5.40.1",
110
+ "@typescript-eslint/parser": "5.40.1",
111
111
  "coffeescript": "2.7.0",
112
112
  "eslint": "8.25.0",
113
113
  "eslint-config-prettier": "8.5.0",
@@ -118,7 +118,7 @@
118
118
  "grunt-contrib-watch": "1.1.0",
119
119
  "grunt-sync": "0.8.2",
120
120
  "husky": "8.0.1",
121
- "jest": "29.2.0",
121
+ "jest": "29.2.1",
122
122
  "pm2": "5.2.2",
123
123
  "prettier": "2.7.1",
124
124
  "pretty-quick": "3.1.3",
package/src/config.env.ts CHANGED
@@ -58,6 +58,9 @@ const config: { [env: string]: IServerOptions } = {
58
58
  },
59
59
  loadLocalConfig: false,
60
60
  mongoose: {
61
+ collation: {
62
+ locale: 'de',
63
+ },
61
64
  uri: 'mongodb://127.0.0.1/nest-server-dev',
62
65
  },
63
66
  port: 3000,
@@ -114,6 +117,9 @@ const config: { [env: string]: IServerOptions } = {
114
117
  },
115
118
  loadLocalConfig: false,
116
119
  mongoose: {
120
+ collation: {
121
+ locale: 'de',
122
+ },
117
123
  uri: 'mongodb://127.0.0.1/nest-server-dev',
118
124
  },
119
125
  port: 3000,
@@ -170,6 +176,9 @@ const config: { [env: string]: IServerOptions } = {
170
176
  },
171
177
  loadLocalConfig: false,
172
178
  mongoose: {
179
+ collation: {
180
+ locale: 'de',
181
+ },
173
182
  uri: 'mongodb://127.0.0.1/nest-server-prod',
174
183
  },
175
184
  port: 3000,
@@ -4,6 +4,7 @@ import { JwtModuleOptions } from '@nestjs/jwt';
4
4
  import { MongooseModuleOptions } from '@nestjs/mongoose';
5
5
  import { ServeStaticOptions } from '@nestjs/platform-express/interfaces/serve-static-options.interface';
6
6
  import { CronExpression } from '@nestjs/schedule';
7
+ import { CollationOptions } from 'mongodb';
7
8
  import * as SMTPTransport from 'nodemailer/lib/smtp-transport';
8
9
  import { Falsy } from '../types/falsy.type';
9
10
  import { CronJobConfig } from './cron-job-config.interface';
@@ -156,7 +157,19 @@ export interface IServerOptions {
156
157
  /**
157
158
  * Configuration for Mongoose
158
159
  */
159
- mongoose?: { uri: string; options?: MongooseModuleOptions };
160
+ mongoose?: {
161
+ collation?: CollationOptions;
162
+
163
+ /**
164
+ * Mongoose connection string
165
+ */
166
+ uri: string;
167
+
168
+ /**
169
+ * Mongoose module options
170
+ */
171
+ options?: MongooseModuleOptions;
172
+ };
160
173
 
161
174
  /**
162
175
  * Port number of the server
@@ -1,3 +1,4 @@
1
+ import { CollationOptions } from 'mongodb';
1
2
  import { Model, PopulateOptions } from 'mongoose';
2
3
  import { FieldSelection } from '../types/field-selection.type';
3
4
  import { PrepareInputOptions } from './prepare-input-options.interface';
@@ -15,6 +16,10 @@ export interface ServiceOptions {
15
16
  // If truly (default): input data will be checked
16
17
  checkRights?: boolean;
17
18
 
19
+ // Collation for mongodb
20
+ // See https://www.mongodb.com/docs/manual/reference/collation/
21
+ collation?: CollationOptions;
22
+
18
23
  // Current user to set ownership, check rights and other things
19
24
  currentUser?: {
20
25
  [key: string]: any;
@@ -7,6 +7,7 @@ import { convertFilterArgsToQuery } from '../helpers/filter.helper';
7
7
  import { assignPlain } from '../helpers/input.helper';
8
8
  import { ServiceOptions } from '../interfaces/service-options.interface';
9
9
  import { CoreModel } from '../models/core-model.model';
10
+ import { ConfigService } from './config.service';
10
11
  import { ModuleService } from './module.service';
11
12
 
12
13
  export abstract class CrudService<T extends CoreModel = any> extends ModuleService<T> {
@@ -100,7 +101,12 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
100
101
  }
101
102
 
102
103
  // Find in DB
103
- return this.mainDbModel.find(filterQuery.filterQuery, null, filterQuery.queryOptions).exec();
104
+ let find = this.mainDbModel.find(filterQuery.filterQuery, null, filterQuery.queryOptions);
105
+ const collation = serviceOptions?.collation || ConfigService.get('mongoose.collation');
106
+ if (collation) {
107
+ find = find.collation(collation);
108
+ }
109
+ return find.exec();
104
110
  },
105
111
  { input: filter, serviceOptions }
106
112
  );
@@ -197,7 +203,9 @@ export abstract class CrudService<T extends CoreModel = any> extends ModuleServi
197
203
  aggregation.push({ $facet: facet });
198
204
 
199
205
  // Find and process db items
200
- const dbResult = (await this.mainDbModel.aggregate(aggregation).exec())[0] || {};
206
+ const collation = serviceOptions?.collation || ConfigService.get('mongoose.collation');
207
+ const dbResult =
208
+ (await this.mainDbModel.aggregate(aggregation, collation ? { collation } : {}).exec())[0] || {};
201
209
  dbResult.totalCount = dbResult.totalCount?.[0]?.total || 0;
202
210
  dbResult.items = dbResult.items?.map((item) => this.mainDbModel.hydrate(item)) || [];
203
211
  return dbResult;