@ecopex/ecopex-framework 1.0.8 → 1.0.9

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": "@ecopex/ecopex-framework",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Javascript Framework for API and Admin Panel",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -30,7 +30,7 @@ async function getAll(request, reply, routeOptions = {}) {
30
30
  const orderBy = `${tableName}.${(splitOrder[0] || primaryKey)}`;
31
31
  const orderDirection = splitOrder[1] || 'desc';
32
32
 
33
- let query = db(tableName + ' as ' + tableName).select(`${tableName}.*`);
33
+ let query = db.instance(tableName + ' as ' + tableName).select(`${tableName}.*`);
34
34
 
35
35
  // Apply search filter if provided
36
36
  if (search && routeConfig.searchable_fields) {
@@ -155,7 +155,7 @@ async function getById(request, reply, routeOptions = {}) {
155
155
  const tableName = routeOptions.tableName || 'users';
156
156
  const routeConfig = routeOptions.routeConfig || {};
157
157
 
158
- const item_query = db(tableName)
158
+ const item_query = db.instance(tableName)
159
159
  .select(`${tableName}.*`)
160
160
  .where(primaryKey, id);
161
161
 
@@ -261,14 +261,14 @@ async function create(request, reply, routeOptions = {}) {
261
261
  }
262
262
 
263
263
  try {
264
- const [id] = await db(tableName)
264
+ const [id] = await db.instance(tableName)
265
265
  .insert({
266
266
  ...data,
267
267
  created_at: new Date(),
268
268
  updated_at: new Date()
269
269
  });
270
270
 
271
- const item = await db(tableName)
271
+ const item = await db.instance(tableName)
272
272
  .where(primaryKey, id)
273
273
  .first();
274
274
 
@@ -345,7 +345,7 @@ async function update(request, reply, routeOptions = {}) {
345
345
 
346
346
 
347
347
  // Check if record exists
348
- const existingItem = await db(tableName)
348
+ const existingItem = await db.instance(tableName)
349
349
  .where(request.params)
350
350
  .first();
351
351
 
@@ -363,14 +363,14 @@ async function update(request, reply, routeOptions = {}) {
363
363
  }
364
364
  }
365
365
 
366
- await db(tableName)
366
+ await db.instance(tableName)
367
367
  .where(request.params)
368
368
  .update({
369
369
  ...data,
370
370
  updated_at: new Date()
371
371
  })
372
372
 
373
- const updatedItem = await db(tableName)
373
+ const updatedItem = await db.instance(tableName)
374
374
  .where(request.params)
375
375
  .first();
376
376
 
@@ -406,7 +406,7 @@ async function upload(request, reply, routeOptions = {}) {
406
406
  const { [primaryKey]: id } = request.params;
407
407
  const routeConfig = routeOptions.routeConfig || {};
408
408
 
409
- const existingItem = await db(tableName)
409
+ const existingItem = await db.instance(tableName)
410
410
  .where(primaryKey, id)
411
411
  .first();
412
412
 
@@ -425,7 +425,7 @@ async function upload(request, reply, routeOptions = {}) {
425
425
  });
426
426
  }
427
427
 
428
- await db(tableName)
428
+ await db.instance(tableName)
429
429
  .where(primaryKey, id)
430
430
  .update({
431
431
  [routeConfig.upload_field]: uploadResult.file.fileUrl
@@ -464,7 +464,7 @@ async function deleteRecord(request, reply, routeOptions = {}) {
464
464
  const tableName = routeOptions.tableName || 'users';
465
465
 
466
466
  // Check if record exists
467
- const existingItem = await db(tableName)
467
+ const existingItem = await db.instance(tableName)
468
468
  .where('id', id)
469
469
  .first();
470
470
 
@@ -475,7 +475,7 @@ async function deleteRecord(request, reply, routeOptions = {}) {
475
475
  });
476
476
  }
477
477
 
478
- await db(tableName)
478
+ await db.instance(tableName)
479
479
  .where('id', id)
480
480
  .del();
481
481
 
@@ -524,7 +524,7 @@ const generateRandomString = async (from_string = null, field_name = null, table
524
524
  * @returns {Promise<boolean>} - The unique status
525
525
  */
526
526
  const checkUnique = async (value = null, field_name = null, tableName = null) => {
527
- const existing_item = await db(tableName).select(field_name).where(field_name, value).first();
527
+ const existing_item = await db.instance(tableName).select(field_name).where(field_name, value).first();
528
528
  return existing_item ? true : false;
529
529
  }
530
530
 
@@ -594,7 +594,7 @@ const processJoinTables = async (items, joinTables) => {
594
594
 
595
595
  const personal_ids = items.map(item => item[joinTable.primary_key]);
596
596
 
597
- const personal_items = db(joinTable.table).whereIn(joinTable.table + '.' + joinTable.foreign_key, personal_ids);
597
+ const personal_items = db.instance(joinTable.table).whereIn(joinTable.table + '.' + joinTable.foreign_key, personal_ids);
598
598
 
599
599
  if(joinTable.extra_where) {
600
600
  personal_items.where(db.raw(joinTable.table + '.' + joinTable.extra_where));
@@ -18,7 +18,7 @@ class Middleware {
18
18
  request.locale = locale;
19
19
  request.t = (key, params = {}) => i18n.t(key, locale, params);
20
20
 
21
- const language = await db('languages').where('code', locale).first();
21
+ const language = await db.instance('languages').where('code', locale).first();
22
22
 
23
23
  request.language = language ? language.language_id : 1;
24
24