zet-lib 1.2.85 → 1.2.87
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/Util.js +1 -1
- package/lib/zAppRouter.js +12 -1
- package/lib/zRoute.js +182 -151
- package/package.json +1 -1
package/lib/Util.js
CHANGED
|
@@ -822,7 +822,7 @@ Util.virtualHelper = function (obj) {
|
|
|
822
822
|
return str
|
|
823
823
|
}
|
|
824
824
|
|
|
825
|
-
Util.nots = ['id', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy', 'companyId', 'created_at', 'updated_at', 'updated_by', 'created_by', 'modified_by', 'company_id', 'token', 'version', 'signin_method', 'lastLogin', 'last_login', 'forgotPassword', 'forgot_password', 'no', 'actionColumn']
|
|
825
|
+
Util.nots = ['id', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy', 'companyId', 'created_at', 'updated_at', 'updated_by', 'created_by', 'modified_by', 'company_id', 'token', 'version', 'signin_method', 'lastLogin', 'last_login', 'forgotPassword', 'forgot_password', 'no', 'actionColumn', 'lock', 'approval_status', 'approval_history']
|
|
826
826
|
|
|
827
827
|
Util.requiredFields = function (obj = {}) {
|
|
828
828
|
var nots = Util.nots
|
package/lib/zAppRouter.js
CHANGED
|
@@ -1593,7 +1593,18 @@ router.post('/zhistory-data', async (req, res) => {
|
|
|
1593
1593
|
order_by: ['id asc'],
|
|
1594
1594
|
})
|
|
1595
1595
|
if (results.length > 0) {
|
|
1596
|
-
let users =
|
|
1596
|
+
let users = {}
|
|
1597
|
+
if (myCache.has('users')) {
|
|
1598
|
+
users = myCache.get('users')
|
|
1599
|
+
} else {
|
|
1600
|
+
users = Util.arrayToObject(
|
|
1601
|
+
await connection.results({
|
|
1602
|
+
table: 'zuser',
|
|
1603
|
+
}),
|
|
1604
|
+
'id'
|
|
1605
|
+
)
|
|
1606
|
+
myCache.set('users', users)
|
|
1607
|
+
}
|
|
1597
1608
|
html = await zRoute.history(req, res, relations, id, MYMODEL, users, results)
|
|
1598
1609
|
}
|
|
1599
1610
|
res.json(html)
|
package/lib/zRoute.js
CHANGED
|
@@ -2314,8 +2314,11 @@ zRoute.forms = (req, res, MYMODEL, relations, data = {}) => {
|
|
|
2314
2314
|
if (obj.value.length > 0) {
|
|
2315
2315
|
obj.value.map((item) => {
|
|
2316
2316
|
let filename = `${dirRoot}/public/uploads/${MYMODEL.table}/${key}/${item}`
|
|
2317
|
-
var
|
|
2318
|
-
|
|
2317
|
+
var fileSizeInBytes = 12345
|
|
2318
|
+
if (Util.fileExist(filename)) {
|
|
2319
|
+
var stats = fs.statSync(filename)
|
|
2320
|
+
fileSizeInBytes = stats.size
|
|
2321
|
+
}
|
|
2319
2322
|
dropzone_data_arr.push({ fileName: item, size: fileSizeInBytes })
|
|
2320
2323
|
})
|
|
2321
2324
|
myCache.set(`dropzone__${res.locals.userId}__${MYMODEL.table}__${key}__${data.id}`, obj.value)
|
|
@@ -3555,160 +3558,168 @@ ${keys}.forEach(function (myobj, index) {
|
|
|
3555
3558
|
MySQL CRUD with context
|
|
3556
3559
|
*/
|
|
3557
3560
|
zRoute.insertSQL = async (req, res, table, data) => {
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
fs.
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3561
|
+
try {
|
|
3562
|
+
const MYMODELS = myCache.get('MYMODELS')
|
|
3563
|
+
let MYMODEL = MYMODELS[table]
|
|
3564
|
+
let fields = MYMODEL.keys
|
|
3565
|
+
let userId = res.locals.userId || 1
|
|
3566
|
+
if (fields.includes('company_id')) data.company_id = res.locals.companyId || 1
|
|
3567
|
+
if (fields.includes('updated_at')) data.updated_at = Util.now()
|
|
3568
|
+
if (fields.includes('created_at')) data.created_at = Util.now()
|
|
3569
|
+
if (fields.includes('updated_by')) data.updated_by = userId
|
|
3570
|
+
if (fields.includes('created_by')) data.created_by = userId
|
|
3571
|
+
delete data.lock
|
|
3572
|
+
delete data.approval_status
|
|
3573
|
+
delete data.approval_history
|
|
3574
|
+
|
|
3575
|
+
//check dropzone
|
|
3576
|
+
let hasDropzone = false
|
|
3577
|
+
for (let key in MYMODEL.widgets) {
|
|
3578
|
+
if (MYMODEL.widgets[key].name === 'dropzone') {
|
|
3579
|
+
//console.log('has dropzone')
|
|
3580
|
+
let path_src = dirRoot + '/public/zdropzone/' + userId + '/'
|
|
3581
|
+
let path_dest = dirRoot + '/public/uploads/' + MYMODEL.routeName + '/' + key + '/'
|
|
3582
|
+
if (!fs.existsSync(path_dest)) {
|
|
3583
|
+
fs.mkdirSync(path_dest, { recursive: true })
|
|
3584
|
+
}
|
|
3585
|
+
let name = `dropzone__${res.locals.userId}__${table}__${key}__create`
|
|
3586
|
+
if (myCache.has(name)) {
|
|
3587
|
+
let arr = myCache.get(name)
|
|
3588
|
+
let newArr = []
|
|
3589
|
+
if (arr.length > 0) {
|
|
3590
|
+
let time = new Date().getTime()
|
|
3591
|
+
arr.map((item) => {
|
|
3592
|
+
let newItem = time + item
|
|
3593
|
+
newArr.push(newItem)
|
|
3594
|
+
fs.rename(path_src + item, path_dest + newItem)
|
|
3595
|
+
})
|
|
3592
3596
|
|
|
3593
|
-
|
|
3597
|
+
data[key] = Util.array_to_jsonb(newArr)
|
|
3598
|
+
}
|
|
3594
3599
|
}
|
|
3595
3600
|
}
|
|
3596
3601
|
}
|
|
3602
|
+
const result = await connection.insert({ table: table, data: data })
|
|
3603
|
+
zRoute.modelsCacheRenew(table, res.locals.companyId)
|
|
3604
|
+
return result
|
|
3605
|
+
} catch (e) {
|
|
3606
|
+
console.log(e)
|
|
3597
3607
|
}
|
|
3598
|
-
const result = await connection.insert({ table: table, data: data })
|
|
3599
|
-
zRoute.modelsCacheRenew(table, res.locals.companyId)
|
|
3600
|
-
return result
|
|
3601
3608
|
}
|
|
3602
3609
|
|
|
3603
3610
|
zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
//check if has table and image/file
|
|
3615
|
-
let hasImages = false
|
|
3616
|
-
let tables = []
|
|
3617
|
-
let tableFields = {}
|
|
3618
|
-
for (let key in MYMODEL.widgets) {
|
|
3619
|
-
if (MYMODEL.widgets[key].name == 'table') {
|
|
3620
|
-
tableFields[key] = []
|
|
3621
|
-
const MYMODEL_TABLE = MYMODELS[MYMODEL.widgets[key].table]
|
|
3622
|
-
for (let q in MYMODEL_TABLE.widgets) {
|
|
3623
|
-
if (MYMODEL_TABLE.widgets[q].name == 'file' || MYMODEL_TABLE.widgets[q].name == 'image') {
|
|
3624
|
-
hasImages = true
|
|
3625
|
-
tables.push(key)
|
|
3626
|
-
tableFields[key].push(q)
|
|
3627
|
-
}
|
|
3628
|
-
}
|
|
3611
|
+
try {
|
|
3612
|
+
const MYMODELS = myCache.get('MYMODELS')
|
|
3613
|
+
let MYMODEL = MYMODELS[table]
|
|
3614
|
+
let fields = MYMODEL.keys
|
|
3615
|
+
const userId = res.locals.userId
|
|
3616
|
+
if (fields.includes('updated_at')) {
|
|
3617
|
+
data.updated_at = Util.now()
|
|
3618
|
+
}
|
|
3619
|
+
if (fields.includes('updated_by')) {
|
|
3620
|
+
data.updated_by = userId
|
|
3629
3621
|
}
|
|
3630
|
-
if
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3622
|
+
//check if has table and image/file
|
|
3623
|
+
let hasImages = false
|
|
3624
|
+
let tables = []
|
|
3625
|
+
let tableFields = {}
|
|
3626
|
+
for (let key in MYMODEL.widgets) {
|
|
3627
|
+
if (MYMODEL.widgets[key].name == 'table') {
|
|
3628
|
+
tableFields[key] = []
|
|
3629
|
+
const MYMODEL_TABLE = MYMODELS[MYMODEL.widgets[key].table]
|
|
3630
|
+
for (let q in MYMODEL_TABLE.widgets) {
|
|
3631
|
+
if (MYMODEL_TABLE.widgets[q].name == 'file' || MYMODEL_TABLE.widgets[q].name == 'image') {
|
|
3632
|
+
hasImages = true
|
|
3633
|
+
tables.push(key)
|
|
3634
|
+
tableFields[key].push(q)
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3636
3637
|
}
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
let
|
|
3640
|
-
let
|
|
3641
|
-
if (
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3638
|
+
if (MYMODEL.widgets[key].name === 'dropzone') {
|
|
3639
|
+
//console.log('has dropzone')
|
|
3640
|
+
let path_src = dirRoot + '/public/zdropzone/' + userId + '/'
|
|
3641
|
+
let path_dest = dirRoot + '/public/uploads/' + MYMODEL.table + '/' + key + '/'
|
|
3642
|
+
if (!fs.existsSync(path_dest)) {
|
|
3643
|
+
fs.mkdirSync(path_dest, { recursive: true })
|
|
3644
|
+
}
|
|
3645
|
+
let name = `dropzone__${userId}__${MYMODEL.table}__${key}__${whereData.id}`
|
|
3646
|
+
if (myCache.has(name)) {
|
|
3647
|
+
let arr = myCache.get(name)
|
|
3648
|
+
let newArr = []
|
|
3649
|
+
if (arr.length > 0) {
|
|
3650
|
+
let time = new Date().getTime()
|
|
3651
|
+
arr.map((item) => {
|
|
3652
|
+
if (!Util.fileExist(path_dest + item)) {
|
|
3653
|
+
let newItem = time + item
|
|
3654
|
+
newArr.push(newItem)
|
|
3655
|
+
fs.rename(path_src + item, path_dest + newItem)
|
|
3656
|
+
} else {
|
|
3657
|
+
newArr.push(item)
|
|
3658
|
+
}
|
|
3659
|
+
})
|
|
3660
|
+
data[key] = Util.array_to_jsonb(newArr)
|
|
3661
|
+
}
|
|
3653
3662
|
}
|
|
3654
3663
|
}
|
|
3655
3664
|
}
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3665
|
+
let result = await connection.result({
|
|
3666
|
+
table: MYMODEL.table,
|
|
3667
|
+
where: whereData,
|
|
3668
|
+
})
|
|
3669
|
+
if (hasImages) {
|
|
3670
|
+
tables.forEach((item) => {
|
|
3671
|
+
let dataTables = data[item] ? JSON.parse(data[item]) : []
|
|
3672
|
+
let temp = []
|
|
3673
|
+
if (dataTables.length) {
|
|
3674
|
+
dataTables.forEach((obj, index) => {
|
|
3675
|
+
tableFields[item].forEach((key) => {
|
|
3676
|
+
if (!obj[key]) {
|
|
3677
|
+
let resultItem = result[item]
|
|
3678
|
+
if (resultItem && Object.prototype.hasOwnProperty.call(resultItem, index)) {
|
|
3679
|
+
let resultItemIndex = resultItem[index]
|
|
3680
|
+
if (resultItemIndex && Object.prototype.hasOwnProperty.call(resultItemIndex, key)) {
|
|
3681
|
+
obj[key] = !result[item][index] ? '' : result[item][index][key]
|
|
3682
|
+
}
|
|
3674
3683
|
}
|
|
3675
3684
|
}
|
|
3676
|
-
}
|
|
3685
|
+
})
|
|
3686
|
+
temp.push(obj)
|
|
3677
3687
|
})
|
|
3678
|
-
|
|
3679
|
-
}
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3688
|
+
data[item] = JSON.stringify(temp)
|
|
3689
|
+
}
|
|
3690
|
+
})
|
|
3691
|
+
}
|
|
3692
|
+
delete data.created_at
|
|
3693
|
+
delete data.created_by
|
|
3694
|
+
delete data.lock
|
|
3695
|
+
delete data.approval_status
|
|
3696
|
+
delete data.approval_history
|
|
3697
|
+
if (result.lock != 1) {
|
|
3698
|
+
const myresult = await connection.update({ table: table, where: whereData, data: data })
|
|
3699
|
+
//save to history
|
|
3700
|
+
connection.insert({
|
|
3701
|
+
table: 'zhistory',
|
|
3702
|
+
data: {
|
|
3703
|
+
module_id: result.id,
|
|
3704
|
+
module: MYMODEL.table,
|
|
3705
|
+
data_1: JSON.stringify(result),
|
|
3706
|
+
data_2: JSON.stringify(myresult),
|
|
3707
|
+
data_1_date: result.updated_at,
|
|
3708
|
+
data_2_date: data.updated_at,
|
|
3709
|
+
created_by: userId,
|
|
3710
|
+
updated_by: userId,
|
|
3711
|
+
created_at: Util.now(),
|
|
3712
|
+
updated_at: Util.now(),
|
|
3713
|
+
company_id: res.locals.companyId,
|
|
3714
|
+
},
|
|
3715
|
+
})
|
|
3716
|
+
zRoute.modelsCacheRenew(table, res.locals.companyId)
|
|
3717
|
+
return myresult
|
|
3718
|
+
} else {
|
|
3719
|
+
return result
|
|
3720
|
+
}
|
|
3721
|
+
} catch (e) {
|
|
3722
|
+
console.log(e)
|
|
3712
3723
|
}
|
|
3713
3724
|
}
|
|
3714
3725
|
|
|
@@ -3746,7 +3757,8 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3746
3757
|
res.json('no access')
|
|
3747
3758
|
return false
|
|
3748
3759
|
}
|
|
3749
|
-
|
|
3760
|
+
const dateTime = Util.now()
|
|
3761
|
+
const companyId = res.locals.companyId
|
|
3750
3762
|
const userId = res.locals.userId
|
|
3751
3763
|
const room = res.locals.token
|
|
3752
3764
|
let progress = 0
|
|
@@ -3864,20 +3876,20 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3864
3876
|
delete data.approval_status
|
|
3865
3877
|
delete data.approval_history
|
|
3866
3878
|
if (isInsert) {
|
|
3867
|
-
if (Util.in_array('company_id', fields)) data.company_id =
|
|
3868
|
-
if (Util.in_array('created_at', fields)) data.created_at =
|
|
3869
|
-
if (Util.in_array('created_by', fields)) data.created_by =
|
|
3870
|
-
if (Util.in_array('updated_at', fields)) data.updated_at =
|
|
3871
|
-
if (Util.in_array('updated_by', fields)) data.updated_by =
|
|
3879
|
+
if (Util.in_array('company_id', fields)) data.company_id = companyId
|
|
3880
|
+
if (Util.in_array('created_at', fields)) data.created_at = dateTime
|
|
3881
|
+
if (Util.in_array('created_by', fields)) data.created_by = userId
|
|
3882
|
+
if (Util.in_array('updated_at', fields)) data.updated_at = dateTime
|
|
3883
|
+
if (Util.in_array('updated_by', fields)) data.updated_by = userId
|
|
3872
3884
|
|
|
3873
3885
|
await connection.insert({ table: MYMODEL.table, data: data })
|
|
3874
3886
|
hd += `<td class='text text-success'>${LANGUAGE['success']}</td>`
|
|
3875
3887
|
} else {
|
|
3876
|
-
if (Util.in_array('updated_at', fields)) data.updated_at =
|
|
3877
|
-
if (Util.in_array('updated_by', fields)) data.updated_by =
|
|
3888
|
+
if (Util.in_array('updated_at', fields)) data.updated_at = dateTime
|
|
3889
|
+
if (Util.in_array('updated_by', fields)) data.updated_by = userId
|
|
3878
3890
|
//check data is lock
|
|
3879
3891
|
let mydatas = await connection.result({
|
|
3880
|
-
select: 'id,lock',
|
|
3892
|
+
//select: 'id,lock',
|
|
3881
3893
|
table: MYMODEL.table,
|
|
3882
3894
|
where: {
|
|
3883
3895
|
id: data.id,
|
|
@@ -3886,7 +3898,7 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3886
3898
|
if (mydatas.lock == 1) {
|
|
3887
3899
|
hd += `<td class='text text-success'>Data is locked</td>`
|
|
3888
3900
|
} else {
|
|
3889
|
-
await connection.update({
|
|
3901
|
+
let myupdate = await connection.update({
|
|
3890
3902
|
table: MYMODEL.table,
|
|
3891
3903
|
data: data,
|
|
3892
3904
|
where: {
|
|
@@ -3894,6 +3906,25 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3894
3906
|
},
|
|
3895
3907
|
})
|
|
3896
3908
|
hd += `<td class='text text-success'>${LANGUAGE['success']}</td>`
|
|
3909
|
+
|
|
3910
|
+
//save to history
|
|
3911
|
+
await connection.insert({
|
|
3912
|
+
table: 'zhistory',
|
|
3913
|
+
data: {
|
|
3914
|
+
data_1: JSON.stringify(mydatas),
|
|
3915
|
+
data_2: JSON.stringify(myupdate),
|
|
3916
|
+
data_1_date: mydatas.updated_at,
|
|
3917
|
+
data_2_date: dateTime,
|
|
3918
|
+
module_id: mydatas.id,
|
|
3919
|
+
module: MYMODEL.table,
|
|
3920
|
+
company_id: companyId,
|
|
3921
|
+
created_at: dateTime,
|
|
3922
|
+
created_by: userId,
|
|
3923
|
+
updated_at: dateTime,
|
|
3924
|
+
updated_by: userId,
|
|
3925
|
+
},
|
|
3926
|
+
})
|
|
3927
|
+
//end history
|
|
3897
3928
|
}
|
|
3898
3929
|
}
|
|
3899
3930
|
} catch (err) {
|
|
@@ -4357,7 +4388,7 @@ zRoute.history = async (req, res, relations, id, MYMODEL, users, results = []) =
|
|
|
4357
4388
|
arrDataAttributes.push({
|
|
4358
4389
|
date1: result.data_1_date,
|
|
4359
4390
|
date2: result.data_2_date,
|
|
4360
|
-
by1: result.data_1.
|
|
4391
|
+
by1: result.data_1.updated_by,
|
|
4361
4392
|
by2: result.created_by,
|
|
4362
4393
|
})
|
|
4363
4394
|
}
|