ismx-nexo-node-app 0.4.153 → 0.4.154

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.
@@ -225,9 +225,10 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
225
225
  return __awaiter(this, arguments, void 0, function* (tableName, select, filters = {}) {
226
226
  if (!this.tables[tableName])
227
227
  throw new Error(`table ${tableName} does not exist`);
228
- let schema = this.tables[tableName][0].schema;
228
+ let [table, schema, column] = [this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils_1.default.camelToSnake(select)];
229
+ if (!PostgresUtils_1.default.columns(table).includes(column))
230
+ throw new Error(`column ${column} does not exist in table ${tableName}`);
229
231
  let { where, values } = this.toWhere(tableName, filters);
230
- let column = PostgresUtils_1.default.snakeToCamel(select);
231
232
  let query = `SELECT json_agg(u.${column}) as list FROM ${schema}.${tableName} u WHERE ${where}`;
232
233
  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 : []; });
233
234
  });
@@ -236,9 +237,10 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
236
237
  return __awaiter(this, arguments, void 0, function* (tableName, select, filters = {}) {
237
238
  if (!this.tables[tableName])
238
239
  throw new Error(`table ${tableName} does not exist`);
239
- let schema = this.tables[tableName][0].schema;
240
+ let [table, schema, column] = [this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils_1.default.camelToSnake(select)];
241
+ if (!PostgresUtils_1.default.columns(table).includes(column))
242
+ throw new Error(`column ${column} does not exist in table ${tableName}`);
240
243
  let { where, values } = this.toWhere(tableName, filters);
241
- let column = PostgresUtils_1.default.snakeToCamel(select);
242
244
  let query = `
243
245
  SELECT json_object_agg(t.${column}, NULL) as list
244
246
  FROM ( SELECT DISTINCT u.${column} FROM ${schema}.${tableName} u WHERE ${where} ) t`;
@@ -56,7 +56,9 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
56
56
  select(tableName: string, select: string, filters?: {
57
57
  [key: string]: Valuable | Array<Valuable>;
58
58
  }): Promise<string[]>;
59
- selectHash<T>(tableName: string, select: string, filters?: Partial<T>): Promise<Hash<Primitive>>;
59
+ selectHash<T>(tableName: string, select: string, filters?: {
60
+ [key: string]: Valuable | Array<Valuable>;
61
+ }): Promise<Hash<Primitive>>;
60
62
  run<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<T[]>;
61
63
  runTable<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<T[]>;
62
64
  runValue<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<Valuable | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.153",
3
+ "version": "0.4.154",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -197,19 +197,23 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
197
197
  async select(tableName: string, select: string, filters: { [key: string]: Valuable | Array<Valuable> }={}): Promise<string[]>
198
198
  {
199
199
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
200
- let schema = this.tables[tableName][0].schema;
200
+ let [ table, schema, column ] = [ this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils.camelToSnake(select) ];
201
+
202
+ if (!PostgresUtils.columns(table).includes(column)) throw new Error(`column ${column} does not exist in table ${tableName}`);
201
203
  let { where, values } = this.toWhere(tableName, filters);
202
- let column = PostgresUtils.snakeToCamel(select);
204
+
203
205
  let query = `SELECT json_agg(u.${column}) as list FROM ${schema}.${tableName} u WHERE ${where}`
204
206
  return this.query<{list:string[]}>(query, values).then((result) => result[0]?.list ?? []);
205
207
  }
206
208
 
207
- async selectHash<T>(tableName: string, select: string, filters: Partial<T> = {}): Promise<Hash<Primitive>>
209
+ async selectHash<T>(tableName: string, select: string, filters: { [key: string]: Valuable | Array<Valuable> }={}): Promise<Hash<Primitive>>
208
210
  {
209
211
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
210
- let schema = this.tables[tableName][0].schema;
211
- let { where, values } = this.toWhere(tableName, filters as any);
212
- let column = PostgresUtils.snakeToCamel(select);
212
+ let [ table, schema, column ] = [ this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils.camelToSnake(select) ];
213
+
214
+ if (!PostgresUtils.columns(table).includes(column)) throw new Error(`column ${column} does not exist in table ${tableName}`);
215
+ let { where, values } = this.toWhere(tableName, filters);
216
+
213
217
  let query = `
214
218
  SELECT json_object_agg(t.${column}, NULL) as list
215
219
  FROM ( SELECT DISTINCT u.${column} FROM ${schema}.${tableName} u WHERE ${where} ) t`;