ismx-nexo-node-app 0.4.27 → 0.4.28

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.
@@ -164,6 +164,22 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
164
164
  return this.query(query, values).then((result) => result[0]);
165
165
  });
166
166
  }
167
+ delete(tableName, id) {
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ return (yield this.deleteAll(tableName, { id }))[0];
170
+ });
171
+ }
172
+ deleteAll(tableName, filters) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ if (!this.tables[tableName])
175
+ throw new Error(`table ${tableName} does not exist`);
176
+ let table = this.tables[tableName];
177
+ let schema = table[0].schema;
178
+ let { where, values } = this.toWhere(tableName, filters);
179
+ let query = `DELETE FROM ${schema}.${tableName} WHERE ${where} RETURNING *`;
180
+ return this.query(query, values);
181
+ });
182
+ }
167
183
  page(tableName_1, sortKey_1) {
168
184
  return __awaiter(this, arguments, void 0, function* (tableName, sortKey, maxResults = 50, pageNumber = 0, filters = {}) {
169
185
  if (!this.tables[tableName])
@@ -204,11 +220,6 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
204
220
  return this.query(query, values).then((result) => { var _a, _b; return (_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : []; });
205
221
  });
206
222
  }
207
- del(tableName, id) {
208
- return __awaiter(this, void 0, void 0, function* () {
209
- throw new Error(`not implemented yet`);
210
- });
211
- }
212
223
  toWhere(tableName, filters = {}, alias = "", index = 1) {
213
224
  let table = this.tables[tableName];
214
225
  let columns = PostgresUtils_1.default.columns(table);
@@ -58,5 +58,6 @@ export default abstract class RepositoryDatabase extends Repository {
58
58
  abstract select(tableName: string, select: string, filters?: {
59
59
  [key: string]: Primitive | Array<Primitive>;
60
60
  }): Promise<string[]>;
61
- abstract del<T>(tableName: string, id: string): Promise<T>;
61
+ abstract delete<T>(tableName: string, id: string): Promise<T>;
62
+ abstract deleteAll<T>(tableName: string, filters: Partial<T>): Promise<T[]>;
62
63
  }
@@ -37,6 +37,8 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
37
37
  [key: string]: Primitive;
38
38
  } | any)[]): Promise<T[]>;
39
39
  update<T>(tableName: string, id: string, object: Partial<T>): Promise<T>;
40
+ delete<T>(tableName: string, id: string): Promise<T>;
41
+ deleteAll<T>(tableName: string, filters: Partial<T>): Promise<T[]>;
40
42
  page<T>(tableName: string, sortKey: string, maxResults?: number, pageNumber?: number, filters?: {
41
43
  [key: string]: Primitive | Array<Primitive>;
42
44
  }): Promise<Pagination<T>>;
@@ -49,7 +51,6 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
49
51
  select(tableName: string, select: string, filters?: {
50
52
  [key: string]: Primitive | Array<Primitive>;
51
53
  }): Promise<string[]>;
52
- del<T>(tableName: string, id: string): Promise<T>;
53
54
  toWhere(tableName: string, filters?: {
54
55
  [key: string]: Primitive | Array<Primitive>;
55
56
  }, alias?: string, index?: number): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.27",
3
+ "version": "0.4.28",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -72,5 +72,7 @@ export default abstract class RepositoryDatabase extends Repository
72
72
 
73
73
  abstract select(tableName: string, select: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<string[]>;
74
74
 
75
- abstract del<T>(tableName: string, id: string): Promise<T>;
75
+ abstract delete<T>(tableName: string, id: string): Promise<T>;
76
+
77
+ abstract deleteAll<T>(tableName: string, filters: Partial<T>): Promise<T[]>;
76
78
  }
@@ -140,6 +140,19 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
140
140
  return this.query<T>(query, values).then((result) => result[0]);
141
141
  }
142
142
 
143
+ async delete<T>(tableName: string, id: string): Promise<T> {
144
+ return (await this.deleteAll(tableName, { id } as any))[0] as T;
145
+ }
146
+
147
+ async deleteAll<T>(tableName: string, filters: Partial<T>): Promise<T[]> {
148
+ if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
149
+ let table = this.tables[tableName];
150
+ let schema = table[0].schema;
151
+ let { where, values } = this.toWhere(tableName, filters as any);
152
+ let query = `DELETE FROM ${schema}.${tableName} WHERE ${where} RETURNING *`;
153
+ return this.query<T>(query, values);
154
+ }
155
+
143
156
  async page<T>(tableName: string, sortKey: string, maxResults: number = 50, pageNumber: number = 0, filters: {[key:string]:Primitive|Array<Primitive>}={}): Promise<Pagination<T>>
144
157
  {
145
158
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
@@ -180,11 +193,6 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
180
193
  return this.query<{list:string[]}>(query, values).then((result) => result[0]?.list ?? []);
181
194
  }
182
195
 
183
- async del<T>(tableName: string, id: string): Promise<T>
184
- {
185
- throw new Error(`not implemented yet`);
186
- }
187
-
188
196
  toWhere(tableName: string, filters: { [key: string]: Primitive | Array<Primitive> }={}, alias:string = "", index=1)
189
197
  {
190
198
  let table = this.tables[tableName];