zet-lib 1.2.40 → 1.2.42
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/lib/zRoute.js +34 -11
- package/package.json +1 -1
package/lib/zRoute.js
CHANGED
|
@@ -2549,6 +2549,9 @@ zRoute.viewForm = (req, res, MYMODEL, relations, data = {}) => {
|
|
|
2549
2549
|
obj[key].type = 'text'
|
|
2550
2550
|
obj[key].value = data[key] || ''
|
|
2551
2551
|
break
|
|
2552
|
+
case 'number':
|
|
2553
|
+
obj[key].value = data[key] ? Util.formatNumber(data[key], ',') : ''
|
|
2554
|
+
break
|
|
2552
2555
|
case 'typeahead':
|
|
2553
2556
|
obj[key].type = 'text'
|
|
2554
2557
|
obj[key].value = relations[key + 'Object'][data[key]] || ''
|
|
@@ -3347,6 +3350,7 @@ zRoute.insertSQL = async (req, res, table, data) => {
|
|
|
3347
3350
|
if (fields.includes('created_at')) data.created_at = Util.now()
|
|
3348
3351
|
if (fields.includes('updated_by')) data.updated_by = res.locals.userId || 1
|
|
3349
3352
|
if (fields.includes('created_by')) data.created_by = res.locals.userId || 1
|
|
3353
|
+
delete data.lock
|
|
3350
3354
|
const result = await connection.insert({ table: table, data: data })
|
|
3351
3355
|
zRoute.modelsCacheRenew(table, res.locals.companyId)
|
|
3352
3356
|
return result
|
|
@@ -3379,11 +3383,11 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
3379
3383
|
}
|
|
3380
3384
|
}
|
|
3381
3385
|
}
|
|
3386
|
+
let result = await connection.result({
|
|
3387
|
+
table: MYMODEL.table,
|
|
3388
|
+
where: whereData,
|
|
3389
|
+
})
|
|
3382
3390
|
if (hasImages) {
|
|
3383
|
-
let result = await connection.result({
|
|
3384
|
-
table: MYMODEL.table,
|
|
3385
|
-
where: whereData,
|
|
3386
|
-
})
|
|
3387
3391
|
tables.forEach((item) => {
|
|
3388
3392
|
let dataTables = data[item] ? JSON.parse(data[item]) : []
|
|
3389
3393
|
let temp = []
|
|
@@ -3408,9 +3412,14 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
3408
3412
|
}
|
|
3409
3413
|
delete data.created_at
|
|
3410
3414
|
delete data.created_by
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3415
|
+
delete data.lock
|
|
3416
|
+
if (result.lock != 1) {
|
|
3417
|
+
const myresult = await connection.update({ table: table, where: whereData, data: data })
|
|
3418
|
+
zRoute.modelsCacheRenew(table, res.locals.companyId)
|
|
3419
|
+
return myresult
|
|
3420
|
+
} else {
|
|
3421
|
+
return result
|
|
3422
|
+
}
|
|
3414
3423
|
}
|
|
3415
3424
|
|
|
3416
3425
|
zRoute.deleteSQL = async (table, id, company_id) => {
|
|
@@ -3435,7 +3444,7 @@ zRoute.deleteSQL = async (table, id, company_id) => {
|
|
|
3435
3444
|
}
|
|
3436
3445
|
return results[0]
|
|
3437
3446
|
} catch (e) {
|
|
3438
|
-
throw Error(e
|
|
3447
|
+
throw Error(e + '')
|
|
3439
3448
|
}
|
|
3440
3449
|
}
|
|
3441
3450
|
|
|
@@ -3568,19 +3577,33 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3568
3577
|
if (Util.in_array('created_by', fields)) data.created_by = res.locals.userId
|
|
3569
3578
|
if (Util.in_array('updated_at', fields)) data.updated_at = Util.now()
|
|
3570
3579
|
if (Util.in_array('updated_by', fields)) data.updated_by = res.locals.userId
|
|
3580
|
+
delete data.lock
|
|
3571
3581
|
await connection.insert({ table: MYMODEL.table, data: data })
|
|
3572
3582
|
} else {
|
|
3573
3583
|
if (Util.in_array('updated_at', fields)) data.updated_at = Util.now()
|
|
3574
3584
|
if (Util.in_array('updated_by', fields)) data.updated_by = res.locals.userId
|
|
3575
|
-
|
|
3585
|
+
delete data.lock
|
|
3586
|
+
//check data is lock
|
|
3587
|
+
let mydatas = await connection.result({
|
|
3588
|
+
select: 'id,lock',
|
|
3576
3589
|
table: MYMODEL.table,
|
|
3577
|
-
data: data,
|
|
3578
3590
|
where: {
|
|
3579
3591
|
id: data.id,
|
|
3580
3592
|
},
|
|
3581
3593
|
})
|
|
3594
|
+
if (mydatas.lock == 1) {
|
|
3595
|
+
hd += `<td class='text text-success'>Data is locked</td>`
|
|
3596
|
+
} else {
|
|
3597
|
+
var update = await connection.update({
|
|
3598
|
+
table: MYMODEL.table,
|
|
3599
|
+
data: data,
|
|
3600
|
+
where: {
|
|
3601
|
+
id: data.id,
|
|
3602
|
+
},
|
|
3603
|
+
})
|
|
3604
|
+
}
|
|
3605
|
+
hd += `<td class='text text-success'>${LANGUAGE['success']}</td>`
|
|
3582
3606
|
}
|
|
3583
|
-
hd += `<td class='text text-success'>${LANGUAGE['success']}</td>`
|
|
3584
3607
|
} catch (err) {
|
|
3585
3608
|
hd += `<td class='text text-danger'>${err + ''}</td>`
|
|
3586
3609
|
io.to(room).emit('error', err + '' + ' ')
|