@rws-framework/db 2.2.6 → 2.2.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.
@@ -1,4 +1,4 @@
1
- import { Collection } from 'mongodb';
1
+ import { Collection, MongoClient } from 'mongodb';
2
2
  import { ITimeSeries } from '../types/ITimeSeries';
3
3
  import { IModel } from '../models/interfaces/IModel';
4
4
  import { IDbConfigHandler } from '../types/DbConfigHandler';
@@ -15,6 +15,7 @@ declare class DBService {
15
15
  constructor(configService: IDbConfigHandler);
16
16
  private connectToDB;
17
17
  reconnect(opts?: IDBClientCreate): void;
18
+ static baseClientConstruct(dbUrl: string): MongoClient;
18
19
  private createBaseMongoClient;
19
20
  private createBaseMongoClientDB;
20
21
  cloneDatabase(source: string, target: string): Promise<void>;
@@ -45,10 +45,14 @@ class DBService {
45
45
  reconnect(opts = null) {
46
46
  this.connectToDB(opts);
47
47
  }
48
+ static baseClientConstruct(dbUrl) {
49
+ const client = new mongodb_1.MongoClient(dbUrl);
50
+ return client;
51
+ }
48
52
  async createBaseMongoClient() {
49
53
  var _a;
50
54
  const dbUrl = ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.dbUrl) || this.configService.get('mongo_url');
51
- const client = new mongodb_1.MongoClient(dbUrl);
55
+ const client = DBService.baseClientConstruct(dbUrl);
52
56
  await client.connect();
53
57
  return client;
54
58
  }
@@ -140,7 +144,7 @@ class DBService {
140
144
  }
141
145
  if (pagination) {
142
146
  const perPage = pagination.per_page || 50;
143
- params.skip = pagination.page * perPage;
147
+ params.skip = (pagination.page || 0) * perPage;
144
148
  params.take = perPage;
145
149
  }
146
150
  const retData = await this.getCollectionHandler(collection).findMany(params);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/db",
3
3
  "private": false,
4
- "version": "2.2.6",
4
+ "version": "2.2.8",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -56,10 +56,17 @@ class DBService {
56
56
  this.connectToDB(opts);
57
57
  }
58
58
 
59
+ static baseClientConstruct(dbUrl: string): MongoClient
60
+ {
61
+ const client = new MongoClient(dbUrl);
62
+
63
+ return client;
64
+ }
65
+
59
66
  private async createBaseMongoClient(): Promise<MongoClient>
60
67
  {
61
68
  const dbUrl = this.opts?.dbUrl || this.configService.get('mongo_url');
62
- const client = new MongoClient(dbUrl);
69
+ const client = DBService.baseClientConstruct(dbUrl);
63
70
 
64
71
  await client.connect();
65
72
 
@@ -70,7 +77,7 @@ class DBService {
70
77
  private async createBaseMongoClientDB(): Promise<Db>
71
78
  {
72
79
  const dbName = this.opts?.dbName || this.configService.get('mongo_db');
73
- const client = await this. createBaseMongoClient();
80
+ const client = await this.createBaseMongoClient();
74
81
  return client.db(dbName);
75
82
  }
76
83
 
@@ -197,7 +204,7 @@ class DBService {
197
204
 
198
205
  if(pagination){
199
206
  const perPage = pagination.per_page || 50;
200
- params.skip = pagination.page * perPage;
207
+ params.skip = (pagination.page || 0) * perPage;
201
208
  params.take = perPage;
202
209
  }
203
210