明树Git Lab

Commit bfd1b08f authored by zengfanpei's avatar zengfanpei

update

parent 23cf8001
......@@ -45,8 +45,10 @@ async function updateDevice(req, res, next) {
let attrMap = {}
let attrs = await DB.CollectAttribute.find({del: 0, enable: true});
attrs.map(o => {attrMap[o._id] = o; attrMap[o.dbKey] = o;return});
let dbKeys = [];
for (let i = 0; i < req.body.thresholds.length; i++) {
const element = req.body.thresholds[i];
dbKeys.push(element.dbKey);
let {dbKey, deviceKey, name, _id} = attrMap[element.dbKey || element.attrId];
await DB.CollectThreshold.findOneAndUpdate({deviceNumber: ret.deviceNumber, dbKey}, {
max: element.max,
......@@ -57,6 +59,8 @@ async function updateDevice(req, res, next) {
name,
}, {upsert: true});
}
//不在dbKeys里面的属性 全部删除
await DB.CollectThreshold.updateMany({deviceNumber: ret.deviceNumber, dbKey: {$nin: dbKeys}}, {del: 1});
}
res.sendData(ret);
......
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