明树Git Lab

Commit b3538b68 authored by zfp1's avatar zfp1

update

parent ee3bb209
Pipeline #105976 passed with stage
in 3 seconds
......@@ -41,11 +41,36 @@ async function createResource(req, res, next) {
async function updateResource(req, res, next) {
try {
const body = req.body;
if (!body.id) {
if (!req.body.id) {
return res.sendError(errorMessage.resourceNotFound)
}
let ress = await DB.Resources.findOne({ where: { id: req.body.id } });
if (!(ress && ress.id)) {
return res.sendError(errorMessage.resourceNotFound)
}
const ret = await DB.Resources.update(body, { where: { id: body.id } });
await DB.ResourcesInfo.destory({ where: { resourceId: ress.id } });
if (req.body.type == 1) {
let ris = [];
for (let index = 0; index < req.body.resourceInfos.length; index++) {
const element = req.body.resourceInfos[index];
element.resourceId = ress.id;
ris.push(element);
}
console.log(ris, "===")
await DB.ResourcesInfo.bulkCreate(ris);
} else if (req.body.type == 2) {
//树结构
let ris = [];
let data = utils.flattenTreeIterative(req.body.resourceInfos);
for (let index = 0; index < data.length; index++) {
const element = data[index];
element.resourceId = ress.id;
ris.push(element);
}
await DB.ResourcesInfo.bulkCreate(ris);
}
const ret = await DB.Resources.update(req.body, { where: { id: req.body.id } });
return res.sendData(ret);
} catch (error) {
next(error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment