nest-knexjs 0.0.4 → 0.0.8

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.
Files changed (52) hide show
  1. package/.github/workflows/codeql-analysis.yml +31 -0
  2. package/LICENSE +1 -1
  3. package/README.md +178 -8
  4. package/dist/common/knex.decorators.d.ts +2 -1
  5. package/dist/common/knex.decorators.js +3 -2
  6. package/dist/common/knex.utils.d.ts +6 -6
  7. package/dist/common/knex.utils.js +10 -18
  8. package/dist/knex-core.module.d.ts +1 -1
  9. package/dist/knex-core.module.js +9 -11
  10. package/dist/knex.module.js +1 -1
  11. package/package.json +29 -29
  12. package/tests/{app → app-knex/app}/app.module.ts +0 -0
  13. package/tests/{app → app-knex/app}/main.ts +0 -0
  14. package/tests/app-knex/app/users/dto/create-user.dto.ts +4 -0
  15. package/tests/app-knex/app/users/dto/update-user.dto.ts +4 -0
  16. package/tests/app-knex/app/users/entities/user.entity.ts +5 -0
  17. package/tests/{app → app-knex/app}/users/users.controller.ts +0 -0
  18. package/tests/{app → app-knex/app}/users/users.module.ts +0 -0
  19. package/tests/{app → app-knex/app}/users/users.service.spec.ts +0 -0
  20. package/tests/{app → app-knex/app}/users/users.service.ts +7 -7
  21. package/tests/{docker-compose.yml → app-knex/docker-compose.yml} +1 -1
  22. package/tests/{knexfile.js → app-knex/knexfile.js} +0 -0
  23. package/tests/{migrations → app-knex/migrations}/20210223224919_api.js +2 -2
  24. package/tests/{seeds → app-knex/seeds}/users.js +6 -6
  25. package/tests/app-multi-database/app/app.module.ts +61 -0
  26. package/tests/app-multi-database/app/main.ts +9 -0
  27. package/tests/app-multi-database/app/post/dto/create-post.dto.ts +4 -0
  28. package/tests/app-multi-database/app/post/dto/update-post.dto.ts +4 -0
  29. package/tests/app-multi-database/app/post/entities/post.entity.ts +5 -0
  30. package/tests/app-multi-database/app/post/post.controller.ts +42 -0
  31. package/tests/app-multi-database/app/post/post.module.ts +10 -0
  32. package/tests/app-multi-database/app/post/post.service.spec.ts +18 -0
  33. package/tests/app-multi-database/app/post/post.service.ts +64 -0
  34. package/tests/app-multi-database/app/users/dto/create-user.dto.ts +4 -0
  35. package/tests/app-multi-database/app/users/dto/update-user.dto.ts +4 -0
  36. package/tests/app-multi-database/app/users/entities/user.entity.ts +5 -0
  37. package/tests/app-multi-database/app/users/users.controller.ts +42 -0
  38. package/tests/app-multi-database/app/users/users.module.ts +9 -0
  39. package/tests/app-multi-database/app/users/users.service.spec.ts +18 -0
  40. package/tests/app-multi-database/app/users/users.service.ts +71 -0
  41. package/tests/app-multi-database/docker-compose.yml +21 -0
  42. package/tests/app-multi-database/knexfile.js +34 -0
  43. package/tests/app-multi-database/migrations/posts/20210902093735_posts.js +11 -0
  44. package/tests/app-multi-database/migrations/users/20210808150144_users.js +11 -0
  45. package/tests/app-multi-database/seeds/posts.js +24 -0
  46. package/tests/app-multi-database/seeds/users.js +23 -0
  47. package/tests/posts.e2e-spec.ts +130 -0
  48. package/tests/user.e2e-spec.ts +119 -0
  49. package/tests/users.e2e-spec.ts +79 -35
  50. package/tests/app/users/dto/create-user.dto.ts +0 -4
  51. package/tests/app/users/dto/update-user.dto.ts +0 -4
  52. package/tests/app/users/entities/user.entity.ts +0 -5
@@ -0,0 +1,31 @@
1
+ name: "CodeQL"
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+ schedule:
9
+ - cron: '0 0 * * *'
10
+
11
+ jobs:
12
+ analyze:
13
+ name: Analyze
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v2
19
+ with:
20
+ fetch-depth: 0
21
+
22
+ - name: Initialize CodeQL
23
+ uses: github/codeql-action/init@v1
24
+ with:
25
+ languages: javascript
26
+
27
+ - name: Autobuild
28
+ uses: github/codeql-action/autobuild@v1
29
+
30
+ - name: Perform CodeQL Analysis
31
+ uses: github/codeql-action/analyze@v1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Tony133
3
+ Copyright (c) 2021-2022 Tony133
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -51,6 +51,7 @@ or
51
51
  - [Usage](#usage)
52
52
  - [KnexModule](#knexmodule)
53
53
  - [ExampleOfUse](#example-of-use)
54
+ - [MultiConnectionsDatabae](#multi-connections-database)
54
55
  - [CreateMigrations](#create-migrations)
55
56
  - [RunMigrations](#run-migrations)
56
57
  - [CreateSeeds](#create-seeds)
@@ -108,12 +109,12 @@ UsersService:
108
109
 
109
110
  ```typescript
110
111
  import { Injectable } from '@nestjs/common';
111
- import Knex from 'knex';
112
- import { InjectModel } from 'nest-knexjs';
112
+ import { Knex } from 'knex';
113
+ import { InjectConnection } from 'nest-knexjs';
113
114
 
114
115
  @Injectable()
115
116
  export class UsersService {
116
- constructor(@InjectModel() private readonly knex: Knex) {}
117
+ constructor(@InjectConnection() private readonly knex: Knex) {}
117
118
 
118
119
  async findAll() {
119
120
  const users = await this.knex.table('users');
@@ -139,6 +140,175 @@ export class UsersController {
139
140
  }
140
141
  ```
141
142
 
143
+ ## Multi Connections Database
144
+
145
+ ```typescript
146
+ @Module({
147
+ imports: [
148
+ KnexModule.forRootAsync(
149
+ {
150
+ useFactory: () => ({
151
+ config: {
152
+ client: 'mysql',
153
+ version: '5.7',
154
+ useNullAsDefault: true,
155
+ connection: {
156
+ host: '127.0.0.1',
157
+ user: 'root',
158
+ port: 3306,
159
+ password: 'root',
160
+ database: 'test1',
161
+ },
162
+ pool: {
163
+ min: 2,
164
+ max: 10,
165
+ },
166
+ },
167
+ }),
168
+ },
169
+ 'db1Connection',
170
+ ),
171
+ KnexModule.forRootAsync(
172
+ {
173
+ useFactory: () => ({
174
+ config: {
175
+ client: 'mysql',
176
+ version: '5.7',
177
+ useNullAsDefault: true,
178
+ connection: {
179
+ host: '127.0.0.1',
180
+ user: 'root',
181
+ port: 3307,
182
+ password: 'root',
183
+ database: 'test2',
184
+ },
185
+ pool: {
186
+ min: 2,
187
+ max: 10,
188
+ },
189
+ },
190
+ }),
191
+ },
192
+ 'db2Connection',
193
+ ),
194
+ ],
195
+ controllers: [],
196
+ providers: [],
197
+ })
198
+ export class AppModule {}
199
+ ```
200
+
201
+ Usage example with Multi Connection
202
+
203
+ PostService:
204
+
205
+ ```typescript
206
+ @Injectable()
207
+ export class PostService {
208
+ constructor(
209
+ @InjectConnection('db2Connection')
210
+ private knexConnection: Knex,
211
+ ) {}
212
+
213
+ async create(createPostDto: CreatePostDto) {
214
+ try {
215
+ const post = await this.knexConnection.table('posts').insert({
216
+ title: createPostDto.title,
217
+ description: createPostDto.description,
218
+ });
219
+
220
+ return post;
221
+ } catch (err) {
222
+ throw new HttpException(err, HttpStatus.BAD_REQUEST);
223
+ }
224
+ }
225
+
226
+ async findAll() {
227
+ console.log(this.knexConnection);
228
+ const posts = await this.knexConnection.table('posts');
229
+ return { posts };
230
+ }
231
+ }
232
+ ```
233
+
234
+ UsersService:
235
+
236
+ ```typescript
237
+ @Injectable()
238
+ export class UsersService {
239
+ constructor(
240
+ @InjectConnection('db1Connection')
241
+ private knexConnection: Knex,
242
+ ) {}
243
+
244
+ async findAll() {
245
+ const users = await this.knexConnection.table('users');
246
+ return { users };
247
+ }
248
+
249
+ async create(createUserDto: CreateUserDto) {
250
+ try {
251
+ const users = await this.knexConnection.table('users').insert({
252
+ firstName: createUserDto.firstName,
253
+ lastName: createUserDto.lastName,
254
+ });
255
+
256
+ return { users };
257
+ } catch (err) {
258
+ throw new HttpException(err, HttpStatus.BAD_REQUEST);
259
+ }
260
+ }
261
+ }
262
+ ```
263
+
264
+
265
+ In `knexfile.js` update with your database configuration settings:
266
+
267
+ ```javascript
268
+ module.exports = {
269
+ development: {
270
+ client: 'mysql',
271
+ version: '5.7',
272
+ connection: {
273
+ name: 'db1Connection',
274
+ host: '127.0.0.1',
275
+ user: 'root',
276
+ port: 3306,
277
+ password: 'root',
278
+ database: 'test1',
279
+ },
280
+ migrations: {
281
+ directory: './migrations/users',
282
+ tableName: '[:name_file_migrations_users]',
283
+ },
284
+ },
285
+ developmentTwo: {
286
+ client: 'mysql',
287
+ version: '5.7',
288
+ connection: {
289
+ name: 'db2Connection',
290
+ host: '127.0.0.1',
291
+ user: 'root',
292
+ port: 3307,
293
+ password: 'root',
294
+ database: 'test2',
295
+ },
296
+ migrations: {
297
+ directory: './migrations/posts',
298
+ tableName: '[:name_file_migrations_posts]',
299
+ },
300
+ },
301
+ };
302
+ ```
303
+
304
+ Run Migrations:
305
+
306
+ ```bash
307
+ $ npx knex migrate:latest --env development
308
+
309
+ $ npx knex migrate:latest --env developmentTwo
310
+ ```
311
+
142
312
  ## Create Migrations
143
313
 
144
314
  ```bash
@@ -153,8 +323,8 @@ exports.up = function(knex) {
153
323
  return knex.schema
154
324
  .createTable('users', function(table) {
155
325
  table.increments('id');
156
- table.string('first_name', 255).notNullable();
157
- table.string('last_name', 255).notNullable();
326
+ table.string('firstName', 255).notNullable();
327
+ table.string('lastName', 255).notNullable();
158
328
  })
159
329
  .createTable('products', function(table) {
160
330
  table.increments('id');
@@ -206,9 +376,9 @@ exports.seed = function (knex) {
206
376
  .del()
207
377
  .then(function () {
208
378
  return knex('users').insert([
209
- { id: 1, first_name: 'firstname1', last_name: 'lastname1' },
210
- { id: 2, first_name: 'firstname2', last_name: 'lastname2' },
211
- { id: 3, first_name: 'firstname3', last_name: 'lastname3' },
379
+ { id: 1, firstName: 'firstName#1', lastName: 'lastName#1' },
380
+ { id: 2, firstName: 'firstName#2', lastName: 'lastName#2' },
381
+ { id: 3, firstName: 'firstName#3', lastName: 'lastName#3' },
212
382
  ]);
213
383
  });
214
384
  };
@@ -1,2 +1,3 @@
1
+ import { KnexModuleOptions } from '../interfaces/knex-options.interface';
1
2
  export declare const InjectModel: (connection?: string) => (target: object, key: string | symbol, index?: number) => void;
2
- export declare const InjectConnection: (connection?: string) => (target: object, key: string | symbol, index?: number) => void;
3
+ export declare const InjectConnection: (connection?: KnexModuleOptions | string) => ParameterDecorator;
@@ -4,7 +4,8 @@ exports.InjectConnection = exports.InjectModel = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const knex_utils_1 = require("./knex.utils");
6
6
  const InjectModel = (connection) => {
7
- return common_1.Inject(knex_utils_1.getConnectionToken(connection));
7
+ return (0, common_1.Inject)((0, knex_utils_1.getConnectionToken)(connection));
8
8
  };
9
9
  exports.InjectModel = InjectModel;
10
- exports.InjectConnection = exports.InjectModel;
10
+ const InjectConnection = (connection) => (0, common_1.Inject)((0, knex_utils_1.getConnectionToken)(connection));
11
+ exports.InjectConnection = InjectConnection;
@@ -1,13 +1,13 @@
1
- import { KnexModuleOptions } from "../interfaces";
2
- import { Observable } from "rxjs";
1
+ import { KnexModuleOptions } from '../interfaces';
2
+ import { Observable } from 'rxjs';
3
3
  /**
4
- * This function generates an injection token for an Repostiory
5
- * @param {Function} This parameter can either be a Repostiory
4
+ * This function generates an injection token for an Model
5
+ * @param {Function} This parameter can either be a Model
6
6
  * @param {string} [connection='default'] Connection name
7
7
  * @returns {string} The Entity injection token
8
8
  */
9
- export declare function getModelToken(entity: Function, connection?: KnexModuleOptions | string): string;
10
- export declare function getConnectionToken(connection?: KnexModuleOptions | string): string | Function;
9
+ export declare function getModelToken(model: Function, connection?: KnexModuleOptions | string): string;
10
+ export declare function getConnectionToken(connection?: KnexModuleOptions | any): string | Function;
11
11
  /**
12
12
  * This function returns a Connection prefix based on the connection name
13
13
  * @param {KnexModuleOptions | string} [connection='default'] This optional parameter is either
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateString = exports.getConnectionName = exports.handleRetry = exports.getConnectionPrefix = exports.getConnectionToken = exports.getModelToken = void 0;
4
- const knex_1 = require("knex");
5
4
  const knex_constants_1 = require("../knex.constants");
6
5
  const operators_1 = require("rxjs/operators");
7
6
  const uuid_1 = require("uuid");
@@ -9,27 +8,21 @@ const common_1 = require("@nestjs/common");
9
8
  const circular_dependency_exception_1 = require("../exceptions/circular-dependency.exception");
10
9
  const logger = new common_1.Logger('KnexModule');
11
10
  /**
12
- * This function generates an injection token for an Repostiory
13
- * @param {Function} This parameter can either be a Repostiory
11
+ * This function generates an injection token for an Model
12
+ * @param {Function} This parameter can either be a Model
14
13
  * @param {string} [connection='default'] Connection name
15
14
  * @returns {string} The Entity injection token
16
15
  */
17
- function getModelToken(entity, connection = knex_constants_1.DEFAULT_CONNECTION_NAME) {
18
- if ((entity === null) || (entity === undefined)) {
16
+ function getModelToken(model, connection = knex_constants_1.DEFAULT_CONNECTION_NAME) {
17
+ if (model === null || model === undefined) {
19
18
  throw new circular_dependency_exception_1.CircularDependencyException('@InjectModel()');
20
19
  }
21
20
  const connectionPrefix = getConnectionPrefix(connection);
22
- return `${connectionPrefix}${entity.name}Repository`;
21
+ return `${connectionPrefix}${model.name}`;
23
22
  }
24
23
  exports.getModelToken = getModelToken;
25
24
  function getConnectionToken(connection = knex_constants_1.DEFAULT_CONNECTION_NAME) {
26
- return knex_constants_1.DEFAULT_CONNECTION_NAME === connection
27
- ? knex_1.knex
28
- : 'string' === typeof connection
29
- ? `${connection}Connection`
30
- : knex_constants_1.DEFAULT_CONNECTION_NAME === connection.name || !connection.name
31
- ? knex_1.knex
32
- : `${connection.name}Connection`;
25
+ return `${connection.name || knex_constants_1.DEFAULT_CONNECTION_NAME}`;
33
26
  }
34
27
  exports.getConnectionToken = getConnectionToken;
35
28
  /**
@@ -52,19 +45,18 @@ function getConnectionPrefix(connection = knex_constants_1.DEFAULT_CONNECTION_NA
52
45
  }
53
46
  exports.getConnectionPrefix = getConnectionPrefix;
54
47
  function handleRetry(retryAttempts = 9, retryDelay = 3000) {
55
- return (source) => source.pipe(operators_1.retryWhen(e => e.pipe(operators_1.scan((errorCount, error) => {
56
- logger.error(`Unable to connect to the database. Retrying (${errorCount +
57
- 1})...`, error.stack);
48
+ return (source) => source.pipe((0, operators_1.retryWhen)((e) => e.pipe((0, operators_1.scan)((errorCount, error) => {
49
+ logger.error(`Unable to connect to the database. Retrying (${errorCount + 1})...`, error.stack);
58
50
  if (errorCount + 1 >= retryAttempts) {
59
51
  throw error;
60
52
  }
61
53
  return errorCount + 1;
62
- }, 0), operators_1.delay(retryDelay))));
54
+ }, 0), (0, operators_1.delay)(retryDelay))));
63
55
  }
64
56
  exports.handleRetry = handleRetry;
65
57
  function getConnectionName(options) {
66
58
  return options && options.name ? options.name : knex_constants_1.DEFAULT_CONNECTION_NAME;
67
59
  }
68
60
  exports.getConnectionName = getConnectionName;
69
- const generateString = () => uuid_1.v4();
61
+ const generateString = () => (0, uuid_1.v4)();
70
62
  exports.generateString = generateString;
@@ -7,7 +7,7 @@ export declare class KnexCoreModule implements OnApplicationShutdown {
7
7
  constructor(options: KnexModuleOptions, moduleRef: ModuleRef);
8
8
  static forRoot(options: KnexModuleOptions, connection?: string): DynamicModule;
9
9
  static forRootAsync(options: KnexModuleAsyncOptions, connection: string): DynamicModule;
10
- onApplicationShutdown(): Promise<void>;
10
+ onApplicationShutdown(): Promise<any>;
11
11
  static createAsyncProviders(options: KnexModuleAsyncOptions): Provider[];
12
12
  static createAsyncOptionsProvider(options: KnexModuleAsyncOptions): Provider;
13
13
  private static createConnectionFactory;
@@ -31,7 +31,7 @@ let KnexCoreModule = KnexCoreModule_1 = class KnexCoreModule {
31
31
  useValue: options,
32
32
  };
33
33
  const connectionProvider = {
34
- provide: knex_utils_1.getConnectionToken(connection),
34
+ provide: (0, knex_utils_1.getConnectionToken)(connection),
35
35
  useFactory: async () => await this.createConnectionFactory(options),
36
36
  };
37
37
  return {
@@ -42,7 +42,7 @@ let KnexCoreModule = KnexCoreModule_1 = class KnexCoreModule {
42
42
  }
43
43
  static forRootAsync(options, connection) {
44
44
  const connectionProvider = {
45
- provide: knex_utils_1.getConnectionToken(connection),
45
+ provide: (0, knex_utils_1.getConnectionToken)(connection),
46
46
  useFactory: async (options) => {
47
47
  return await this.createConnectionFactory(options);
48
48
  },
@@ -56,7 +56,7 @@ let KnexCoreModule = KnexCoreModule_1 = class KnexCoreModule {
56
56
  };
57
57
  }
58
58
  async onApplicationShutdown() {
59
- const connection = this.moduleRef.get(knex_utils_1.getConnectionToken(this.options));
59
+ const connection = this.moduleRef.get((0, knex_utils_1.getConnectionToken)(this.options));
60
60
  connection && (await connection.destroy());
61
61
  }
62
62
  static createAsyncProviders(options) {
@@ -93,17 +93,15 @@ let KnexCoreModule = KnexCoreModule_1 = class KnexCoreModule {
93
93
  };
94
94
  }
95
95
  static async createConnectionFactory(options) {
96
- return await rxjs_1.defer(async () => {
97
- return knex_1.knex(options.config);
98
- })
99
- .pipe(knex_utils_1.handleRetry(options.retryAttempts, options.retryDelay))
100
- .toPromise();
96
+ return (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(async () => {
97
+ return (0, knex_1.knex)(options.config);
98
+ }).pipe((0, knex_utils_1.handleRetry)(options.retryAttempts, options.retryDelay)));
101
99
  }
102
100
  };
103
101
  KnexCoreModule = KnexCoreModule_1 = __decorate([
104
- common_1.Global(),
105
- common_1.Module({}),
106
- __param(0, common_1.Inject(knex_constants_1.KNEX_MODULE_OPTIONS)),
102
+ (0, common_1.Global)(),
103
+ (0, common_1.Module)({}),
104
+ __param(0, (0, common_1.Inject)(knex_constants_1.KNEX_MODULE_OPTIONS)),
107
105
  __metadata("design:paramtypes", [Object, core_1.ModuleRef])
108
106
  ], KnexCoreModule);
109
107
  exports.KnexCoreModule = KnexCoreModule;
@@ -25,6 +25,6 @@ let KnexModule = KnexModule_1 = class KnexModule {
25
25
  }
26
26
  };
27
27
  KnexModule = KnexModule_1 = __decorate([
28
- common_1.Module({})
28
+ (0, common_1.Module)({})
29
29
  ], KnexModule);
30
30
  exports.KnexModule = KnexModule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nest-knexjs",
3
- "version": "0.0.4",
3
+ "version": "0.0.8",
4
4
  "description": "Knexjs module for Nest framework (node.js) 😻",
5
5
  "author": "Tony133",
6
6
  "license": "MIT",
@@ -18,41 +18,41 @@
18
18
  "release": "release-it"
19
19
  },
20
20
  "devDependencies": {
21
- "@commitlint/cli": "12.1.4",
22
- "@commitlint/config-angular": "12.1.4",
23
- "@nestjs/common": "7.6.18",
24
- "@nestjs/core": "7.6.18",
25
- "@nestjs/platform-express": "7.6.18",
26
- "@nestjs/testing": "7.6.18",
27
- "@types/express": "4.17.12",
28
- "@types/jest": "26.0.23",
29
- "@types/node": "14.17.4",
21
+ "@commitlint/cli": "16.1.0",
22
+ "@commitlint/config-angular": "16.0.0",
23
+ "@nestjs/common": "8.2.6",
24
+ "@nestjs/core": "8.2.6",
25
+ "@nestjs/platform-express": "8.2.6",
26
+ "@nestjs/testing": "8.2.6",
27
+ "@types/express": "4.17.13",
28
+ "@types/node": "16.11.21",
29
+ "@types/jest": "27.4.0",
30
30
  "@types/supertest": "2.0.11",
31
- "@typescript-eslint/eslint-plugin": "4.28.1",
32
- "@typescript-eslint/parser": "4.28.1",
33
- "eslint": "7.30.0",
31
+ "@typescript-eslint/eslint-plugin": "5.10.1",
32
+ "@typescript-eslint/parser": "5.10.1",
33
+ "eslint": "8.8.0",
34
34
  "eslint-config-prettier": "8.3.0",
35
- "eslint-plugin-import": "2.23.4",
36
- "knex": "0.95.6",
35
+ "eslint-plugin-import": "2.25.4",
36
+ "knex": "1.0.1",
37
37
  "mysql": "2.18.1",
38
- "husky": "7.0.0",
39
- "jest": "27.0.6",
40
- "prettier": "2.3.2",
38
+ "husky": "7.0.4",
39
+ "prettier": "2.5.1",
40
+ "jest": "27.4.7",
41
41
  "reflect-metadata": "0.1.13",
42
- "release-it": "14.10.0",
43
- "supertest": "6.1.3",
44
- "rxjs": "7.1.0",
45
- "ts-node": "10.0.0",
46
- "ts-jest": "27.0.3",
47
- "tsconfig-paths": "3.9.0",
48
- "typescript": "4.3.5"
42
+ "release-it": "14.12.4",
43
+ "supertest": "6.2.2",
44
+ "ts-node": "10.4.0",
45
+ "rxjs": "7.5.2",
46
+ "ts-jest": "27.1.3",
47
+ "tsconfig-paths": "3.12.0",
48
+ "typescript": "4.5.5"
49
49
  },
50
50
  "peerDependencies": {
51
- "@nestjs/common": "^7.0.0",
52
- "@nestjs/core": "^7.0.0",
51
+ "@nestjs/common": "^7.0.0 || ^8.0.0",
52
+ "@nestjs/core": "^7.0.0 || ^8.0.0",
53
53
  "reflect-metadata": "^0.1.13",
54
- "rxjs": "^6.6.3 || ^7.0.0",
55
- "knex": "^0.21.17 || ^0.95.0"
54
+ "rxjs": "^6.6.3 || ^7.2.0",
55
+ "knex": "^0.21.17 || ^0.95.0 || ^1.0.0"
56
56
  },
57
57
  "lint-staged": {
58
58
  "*.ts": [
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ export class CreateUserDto {
2
+ firstName: string;
3
+ lastName: string;
4
+ }
@@ -0,0 +1,4 @@
1
+ export class UpdateUserDto {
2
+ firstName: string;
3
+ lastName: string;
4
+ }
@@ -0,0 +1,5 @@
1
+ export class User {
2
+ id: number;
3
+ firstName: string;
4
+ lastName: string;
5
+ }
@@ -5,7 +5,7 @@ import {
5
5
  NotFoundException,
6
6
  } from '@nestjs/common';
7
7
  import { Knex } from 'knex';
8
- import { InjectModel } from '../../../lib';
8
+ import { InjectModel } from '../../../../lib';
9
9
  import { CreateUserDto } from './dto/create-user.dto';
10
10
  import { UpdateUserDto } from './dto/update-user.dto';
11
11
 
@@ -21,8 +21,8 @@ export class UsersService {
21
21
  async create(createUserDto: CreateUserDto) {
22
22
  try {
23
23
  const users = await this.knex.table('user').insert({
24
- first_name: createUserDto.first_name,
25
- last_name: createUserDto.last_name,
24
+ firstName: createUserDto.firstName,
25
+ lastName: createUserDto.lastName,
26
26
  });
27
27
 
28
28
  return { users };
@@ -33,7 +33,7 @@ export class UsersService {
33
33
 
34
34
  async findOne(id: number) {
35
35
  if (!id) {
36
- throw new NotFoundException('Customer ID does not exist');
36
+ throw new NotFoundException('User ID does not exist');
37
37
  }
38
38
  const users = await this.knex.table('user').where('id', id);
39
39
  return { users };
@@ -42,8 +42,8 @@ export class UsersService {
42
42
  async update(id: number, updateUserDto: UpdateUserDto) {
43
43
  try {
44
44
  const users = await this.knex.table('user').where('id', id).update({
45
- first_name: updateUserDto.first_name,
46
- last_name: updateUserDto.last_name,
45
+ firstName: updateUserDto.firstName,
46
+ lastName: updateUserDto.lastName,
47
47
  });
48
48
 
49
49
  return { users };
@@ -54,7 +54,7 @@ export class UsersService {
54
54
 
55
55
  async remove(id: number) {
56
56
  if (!id) {
57
- throw new NotFoundException('Customer ID does not exist');
57
+ throw new NotFoundException('User ID does not exist');
58
58
  }
59
59
  const users = await this.knex.table('user').where('id', id).del();
60
60
  return { users };
@@ -9,4 +9,4 @@ services:
9
9
  MYSQL_ROOT_PASSWORD: root
10
10
  MYSQL_DATABASE: test
11
11
  ports:
12
- - "3306:3306"
12
+ - "3308:3306"
File without changes
@@ -1,8 +1,8 @@
1
1
  exports.up = function (knex) {
2
2
  return knex.schema.createTable('user', function (table) {
3
3
  table.increments('id');
4
- table.string('first_name', 255).notNullable();
5
- table.string('last_name', 255).notNullable();
4
+ table.string('firstName', 255).notNullable();
5
+ table.string('lastName', 255).notNullable();
6
6
  });
7
7
  };
8
8
 
@@ -5,18 +5,18 @@ exports.seed = function (knex) {
5
5
  return knex('user').insert([
6
6
  {
7
7
  id: 1,
8
- first_name: 'firstName #1',
9
- last_name: 'lastName #1',
8
+ firstName: 'firstName #1',
9
+ lastName: 'lastName #1',
10
10
  },
11
11
  {
12
12
  id: 2,
13
- first_name: 'firstName #1',
14
- last_name: 'lastName #1',
13
+ firstName: 'firstName #2',
14
+ lastName: 'lastName #2',
15
15
  },
16
16
  {
17
17
  id: 3,
18
- first_name: 'firstName #1',
19
- last_name: 'lastName #1',
18
+ firstName: 'firstName #3',
19
+ lastName: 'lastName #3',
20
20
  },
21
21
  ]);
22
22
  });