zet-lib 1.2.40 → 1.2.41

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 (2) hide show
  1. package/lib/zRoute.js +31 -11
  2. package/package.json +1 -1
package/lib/zRoute.js CHANGED
@@ -3347,6 +3347,7 @@ zRoute.insertSQL = async (req, res, table, data) => {
3347
3347
  if (fields.includes('created_at')) data.created_at = Util.now()
3348
3348
  if (fields.includes('updated_by')) data.updated_by = res.locals.userId || 1
3349
3349
  if (fields.includes('created_by')) data.created_by = res.locals.userId || 1
3350
+ delete data.lock
3350
3351
  const result = await connection.insert({ table: table, data: data })
3351
3352
  zRoute.modelsCacheRenew(table, res.locals.companyId)
3352
3353
  return result
@@ -3379,11 +3380,11 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
3379
3380
  }
3380
3381
  }
3381
3382
  }
3383
+ let result = await connection.result({
3384
+ table: MYMODEL.table,
3385
+ where: whereData,
3386
+ })
3382
3387
  if (hasImages) {
3383
- let result = await connection.result({
3384
- table: MYMODEL.table,
3385
- where: whereData,
3386
- })
3387
3388
  tables.forEach((item) => {
3388
3389
  let dataTables = data[item] ? JSON.parse(data[item]) : []
3389
3390
  let temp = []
@@ -3408,9 +3409,14 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
3408
3409
  }
3409
3410
  delete data.created_at
3410
3411
  delete data.created_by
3411
- const result = await connection.update({ table: table, where: whereData, data: data })
3412
- zRoute.modelsCacheRenew(table, res.locals.companyId)
3413
- return result
3412
+ delete data.lock
3413
+ if (result.lock != 1) {
3414
+ const myresult = await connection.update({ table: table, where: whereData, data: data })
3415
+ zRoute.modelsCacheRenew(table, res.locals.companyId)
3416
+ return myresult
3417
+ } else {
3418
+ return result
3419
+ }
3414
3420
  }
3415
3421
 
3416
3422
  zRoute.deleteSQL = async (table, id, company_id) => {
@@ -3435,7 +3441,7 @@ zRoute.deleteSQL = async (table, id, company_id) => {
3435
3441
  }
3436
3442
  return results[0]
3437
3443
  } catch (e) {
3438
- throw Error(e.toString())
3444
+ throw Error(e + '')
3439
3445
  }
3440
3446
  }
3441
3447
 
@@ -3568,19 +3574,33 @@ zRoute.import = async (req, res, MYMODEL) => {
3568
3574
  if (Util.in_array('created_by', fields)) data.created_by = res.locals.userId
3569
3575
  if (Util.in_array('updated_at', fields)) data.updated_at = Util.now()
3570
3576
  if (Util.in_array('updated_by', fields)) data.updated_by = res.locals.userId
3577
+ delete data.lock
3571
3578
  await connection.insert({ table: MYMODEL.table, data: data })
3572
3579
  } else {
3573
3580
  if (Util.in_array('updated_at', fields)) data.updated_at = Util.now()
3574
3581
  if (Util.in_array('updated_by', fields)) data.updated_by = res.locals.userId
3575
- var update = await connection.update({
3582
+ delete data.lock
3583
+ //check data is lock
3584
+ let mydatas = await connection.result({
3585
+ select: 'id,lock',
3576
3586
  table: MYMODEL.table,
3577
- data: data,
3578
3587
  where: {
3579
3588
  id: data.id,
3580
3589
  },
3581
3590
  })
3591
+ if (mydatas.lock == 1) {
3592
+ hd += `<td class='text text-success'>Data is locked</td>`
3593
+ } else {
3594
+ var update = await connection.update({
3595
+ table: MYMODEL.table,
3596
+ data: data,
3597
+ where: {
3598
+ id: data.id,
3599
+ },
3600
+ })
3601
+ }
3602
+ hd += `<td class='text text-success'>${LANGUAGE['success']}</td>`
3582
3603
  }
3583
- hd += `<td class='text text-success'>${LANGUAGE['success']}</td>`
3584
3604
  } catch (err) {
3585
3605
  hd += `<td class='text text-danger'>${err + ''}</td>`
3586
3606
  io.to(room).emit('error', err + '' + ' ')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.2.40",
3
+ "version": "1.2.41",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"