明树Git Lab

Commit 2074bb58 authored by zfp1's avatar zfp1

update

parent dc52e81e
Pipeline #103934 passed with stage
in 3 seconds
...@@ -9,31 +9,16 @@ const { Op } = require('sequelize'); ...@@ -9,31 +9,16 @@ const { Op } = require('sequelize');
async function createResource(req, res, next) { async function createResource(req, res, next) {
try { try {
const body = req.body; const body = req.body;
// await DB.Resources.bulkCreate(
// [
// { "key": "k1a92f", "name": "公交车" },
// { "key": "u3b81x", "name": "地铁" },
// { "key": "p9c44m", "name": "高铁" },
// { "key": "n7d22t", "name": "出租车" },
// { "key": "q4e93z", "name": "轻轨" },
// { "key": "t6f81k", "name": "磁悬浮列车" },
// { "key": "r8g55w", "name": "轮渡" },
// { "key": "s2h19p", "name": "共享单车" },
// { "key": "w9j73v", "name": "电动车" },
// { "key": "a5k33q", "name": "自驾车" },
// { "key": "y1l87u", "name": "长途客车" },
// { "key": "d3m41b", "name": "飞机" },
// { "key": "f8n22h", "name": "直升机" },
// { "key": "c4p66r", "name": "城际铁路" },
// { "key": "m2q99s", "name": "轨道交通" },
// { "key": "j7r55d", "name": "大巴车" },
// { "key": "z3s13e", "name": "顺风车" },
// { "key": "e9t80y", "name": "三轮车" },
// { "key": "h5u28i", "name": "地面有轨电车" },
// { "key": "b6v71o", "name": "高速公路客运" }
// ]
// )
const ret = await DB.Resources.create(body); const ret = await DB.Resources.create(body);
if (body.resourcesInfos && body.resourcesInfos.length && ret.id) {
let ris = [];
for (let index = 0; index < array.length; index++) {
const element = array[index];
element.resourceId = ret.id;
ris.push(element);
}
await DB.ResourcesInfo.bulkCreate(ris);
}
return res.sendData(ret); return res.sendData(ret);
} catch (error) { } catch (error) {
next(error); next(error);
...@@ -187,7 +172,7 @@ async function saveAllResourceInfo(req, res, next) { ...@@ -187,7 +172,7 @@ async function saveAllResourceInfo(req, res, next) {
if (!resource) { if (!resource) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
if(resource && resource.type == 2) { if (resource && resource.type == 2) {
data = utils.disTree(data) data = utils.disTree(data)
} }
let toCreate = [], toKeep = []; let toCreate = [], toKeep = [];
...@@ -202,12 +187,12 @@ async function saveAllResourceInfo(req, res, next) { ...@@ -202,12 +187,12 @@ async function saveAllResourceInfo(req, res, next) {
} }
} }
} }
if(toKeep.length) { if (toKeep.length) {
await DB.ResourcesInfo.destory({ await DB.ResourcesInfo.destory({
where: {[Op.nin]: toKeep} where: { [Op.nin]: toKeep }
}) })
} }
if(toCreate.length) { if (toCreate.length) {
await DB.ResourcesInfo.bulkCreate(toCreate); await DB.ResourcesInfo.bulkCreate(toCreate);
} }
return res.sendData(); return res.sendData();
...@@ -233,7 +218,7 @@ async function listResourceAll(req, res, next) { ...@@ -233,7 +218,7 @@ async function listResourceAll(req, res, next) {
let obj = {}; let obj = {};
for (let index = 0; index < datas.length; index++) { for (let index = 0; index < datas.length; index++) {
const element = datas[index]; const element = datas[index];
if(element.type == 2) { if (element.type == 2) {
element.resourcesInfos = utils.buildTree(element.resourcesInfos); element.resourcesInfos = utils.buildTree(element.resourcesInfos);
} }
obj[element.key] = element.resourcesInfos || []; obj[element.key] = element.resourcesInfos || [];
......
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