|
|
@ -6,70 +6,69 @@ import ncMetaAclMw from '../../helpers/ncMetaAclMw'; |
|
|
|
import { getViewAndModelFromRequestByAliasOrId } from './helpers'; |
|
|
|
import { getViewAndModelFromRequestByAliasOrId } from './helpers'; |
|
|
|
import apiMetrics from '../../helpers/apiMetrics'; |
|
|
|
import apiMetrics from '../../helpers/apiMetrics'; |
|
|
|
|
|
|
|
|
|
|
|
async function bulkDataInsert(req: Request, res: Response) { |
|
|
|
async function getModelAndBase(req: Request) { |
|
|
|
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
|
|
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
|
|
|
|
|
|
|
|
|
|
const base = await Base.get(model.base_id); |
|
|
|
const base = await Base.get(model.base_id); |
|
|
|
|
|
|
|
return { model, view, base }; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function executeBulkOperation( |
|
|
|
|
|
|
|
req: Request, |
|
|
|
|
|
|
|
res: Response, |
|
|
|
|
|
|
|
operation: string, |
|
|
|
|
|
|
|
options: any = {} |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
const { model, view, base } = await getModelAndBase(req); |
|
|
|
const baseModel = await Model.getBaseModelSQL({ |
|
|
|
const baseModel = await Model.getBaseModelSQL({ |
|
|
|
id: model.id, |
|
|
|
id: model.id, |
|
|
|
viewId: view?.id, |
|
|
|
viewId: view?.id, |
|
|
|
dbDriver: NcConnectionMgrv2.get(base), |
|
|
|
dbDriver: NcConnectionMgrv2.get(base), |
|
|
|
|
|
|
|
}).catch((error) => { |
|
|
|
|
|
|
|
res.status(500).json(error); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
if (!baseModel) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const sqlResult = await baseModel[operation](...options).catch((error) => { |
|
|
|
|
|
|
|
res.status(500).json(error); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
res.json(sqlResult); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res.json(await baseModel.bulkInsert(req.body, { cookie: req })); |
|
|
|
async function bulkDataInsert(req: Request, res: Response) { |
|
|
|
|
|
|
|
await executeBulkOperation(req, res, 'bulkInsert', [ |
|
|
|
|
|
|
|
req.body, |
|
|
|
|
|
|
|
{ cookie: req }, |
|
|
|
|
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function bulkDataUpdate(req: Request, res: Response) { |
|
|
|
async function bulkDataUpdate(req: Request, res: Response) { |
|
|
|
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
|
|
await executeBulkOperation(req, res, 'bulkUpdate', [ |
|
|
|
const base = await Base.get(model.base_id); |
|
|
|
req.body, |
|
|
|
|
|
|
|
{ cookie: req }, |
|
|
|
const baseModel = await Model.getBaseModelSQL({ |
|
|
|
]); |
|
|
|
id: model.id, |
|
|
|
|
|
|
|
viewId: view?.id, |
|
|
|
|
|
|
|
dbDriver: NcConnectionMgrv2.get(base), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.json(await baseModel.bulkUpdate(req.body, { cookie: req })); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// todo: Integrate with filterArrJson bulkDataUpdateAll
|
|
|
|
// todo: Integrate with filterArrJson bulkDataUpdateAll
|
|
|
|
async function bulkDataUpdateAll(req: Request, res: Response) { |
|
|
|
async function bulkDataUpdateAll(req: Request, res: Response) { |
|
|
|
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
|
|
await executeBulkOperation(req, res, 'bulkUpdateAll', [ |
|
|
|
const base = await Base.get(model.base_id); |
|
|
|
req.query, |
|
|
|
|
|
|
|
req.body, |
|
|
|
const baseModel = await Model.getBaseModelSQL({ |
|
|
|
{ cookie: req }, |
|
|
|
id: model.id, |
|
|
|
]); |
|
|
|
viewId: view?.id, |
|
|
|
|
|
|
|
dbDriver: NcConnectionMgrv2.get(base), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.json(await baseModel.bulkUpdateAll(req.query, req.body, { cookie: req })); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function bulkDataDelete(req: Request, res: Response) { |
|
|
|
async function bulkDataDelete(req: Request, res: Response) { |
|
|
|
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
|
|
await executeBulkOperation(req, res, 'bulkDelete', [ |
|
|
|
const base = await Base.get(model.base_id); |
|
|
|
req.body, |
|
|
|
const baseModel = await Model.getBaseModelSQL({ |
|
|
|
{ cookie: req }, |
|
|
|
id: model.id, |
|
|
|
]); |
|
|
|
viewId: view?.id, |
|
|
|
|
|
|
|
dbDriver: NcConnectionMgrv2.get(base), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.json(await baseModel.bulkDelete(req.body, { cookie: req })); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// todo: Integrate with filterArrJson bulkDataDeleteAll
|
|
|
|
// todo: Integrate with filterArrJson bulkDataDeleteAll
|
|
|
|
async function bulkDataDeleteAll(req: Request, res: Response) { |
|
|
|
async function bulkDataDeleteAll(req: Request, res: Response) { |
|
|
|
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
|
|
await executeBulkOperation(req, res, 'bulkDeleteAll', [req.query]); |
|
|
|
const base = await Base.get(model.base_id); |
|
|
|
|
|
|
|
const baseModel = await Model.getBaseModelSQL({ |
|
|
|
|
|
|
|
id: model.id, |
|
|
|
|
|
|
|
viewId: view?.id, |
|
|
|
|
|
|
|
dbDriver: NcConnectionMgrv2.get(base), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.json(await baseModel.bulkDeleteAll(req.query)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
const router = Router({ mergeParams: true }); |
|
|
|
const router = Router({ mergeParams: true }); |
|
|
|
|
|
|
|
|
|
|
|