|
|
@ -66,11 +66,12 @@ export class DataTableService { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// if array then do bulk insert
|
|
|
|
// if array then do bulk insert
|
|
|
|
if (Array.isArray(param.body)) { |
|
|
|
const result = await baseModel.bulkInsert( |
|
|
|
return await baseModel.bulkInsert(param.body, { cookie: param.cookie }); |
|
|
|
Array.isArray(param.body) ? param.body : [param.body], |
|
|
|
} else { |
|
|
|
{ cookie: param.cookie, insertOneByOneAsFallback: true }, |
|
|
|
return await baseModel.insert(param.body, null, param.cookie); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Array.isArray(param.body) ? result : result[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async dataUpdate(param: { |
|
|
|
async dataUpdate(param: { |
|
|
@ -119,7 +120,7 @@ export class DataTableService { |
|
|
|
const baseModel = await Model.getBaseModelSQL({ |
|
|
|
const baseModel = await Model.getBaseModelSQL({ |
|
|
|
id: model.id, |
|
|
|
id: model.id, |
|
|
|
viewId: view?.id, |
|
|
|
viewId: view?.id, |
|
|
|
dbDriver: await NcConnectionMgrv2.get(base) |
|
|
|
dbDriver: await NcConnectionMgrv2.get(base), |
|
|
|
}); |
|
|
|
}); |
|
|
|
//
|
|
|
|
//
|
|
|
|
// // todo: Should have error http status code
|
|
|
|
// // todo: Should have error http status code
|
|
|
@ -129,7 +130,6 @@ export class DataTableService { |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return await baseModel.delByPk(param.rowId, null, param.cookie);
|
|
|
|
// return await baseModel.delByPk(param.rowId, null, param.cookie);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const res = await baseModel.bulkUpdate( |
|
|
|
const res = await baseModel.bulkUpdate( |
|
|
|
Array.isArray(param.body) ? param.body : [param.body], |
|
|
|
Array.isArray(param.body) ? param.body : [param.body], |
|
|
|
{ cookie: param.cookie }, |
|
|
|
{ cookie: param.cookie }, |
|
|
@ -190,4 +190,29 @@ export class DataTableService { |
|
|
|
|
|
|
|
|
|
|
|
return { model, view }; |
|
|
|
return { model, view }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async extractPks({ model, rows }: { rows: any[]; model?: Model }) { |
|
|
|
|
|
|
|
return await Promise.all( |
|
|
|
|
|
|
|
rows.map(async (row) => { |
|
|
|
|
|
|
|
// if not object then return the value
|
|
|
|
|
|
|
|
if (typeof row !== 'object') return row; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let pk; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if model is passed then use the model to get the pk columns and extract the pk values
|
|
|
|
|
|
|
|
if (model) { |
|
|
|
|
|
|
|
pk = await model.getColumns().then((cols) => |
|
|
|
|
|
|
|
cols |
|
|
|
|
|
|
|
.filter((col) => col.pk) |
|
|
|
|
|
|
|
.map((col) => row[col.title]) |
|
|
|
|
|
|
|
.join('___'), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// if model is not passed then get all the values and join them
|
|
|
|
|
|
|
|
pk = Object.values(row).join('___'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pk; |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|