明树Git Lab

Commit 83a1ca9d authored by zengfanpei's avatar zengfanpei

update

parent d46725c0
...@@ -55,6 +55,9 @@ async function getDepartInfo(req, res, next) { ...@@ -55,6 +55,9 @@ async function getDepartInfo(req, res, next) {
async function updateDepart(req, res, next) { async function updateDepart(req, res, next) {
try { try {
if(!req.body._id) {
res.sendError(errorMessage.resourceNotFound)
}
let updateObj = { let updateObj = {
...req.body, ...req.body,
_id: undefined, _id: undefined,
...@@ -71,6 +74,10 @@ async function updateDepart(req, res, next) { ...@@ -71,6 +74,10 @@ async function updateDepart(req, res, next) {
updateObj.parentId = req.body.parentId; updateObj.parentId = req.body.parentId;
updateObj.parentIds = parentIds; updateObj.parentIds = parentIds;
} }
//如果用此接口删除
if(req.body.del == 1) {
await DB.User.updateMany({depart: req.body._id}, {depart: null})
}
let ret = await departModule.findOneAndUpdate({ _id: req.body._id }, updateObj); let ret = await departModule.findOneAndUpdate({ _id: req.body._id }, updateObj);
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
......
...@@ -331,6 +331,9 @@ async function updateRole(req, res, next) { ...@@ -331,6 +331,9 @@ async function updateRole(req, res, next) {
async function deleteRole(req, res, next) { async function deleteRole(req, res, next) {
try { try {
if(!req.body._id) {
res.sendError(errorMessage.resourceNotFound)
}
// 角色删除 将用户中的角色去掉。$pull 从数组中删除一个指定元素 // 角色删除 将用户中的角色去掉。$pull 从数组中删除一个指定元素
await DB.User.updateMany({}, {$pull: {roles: (req.body._id)}}); await DB.User.updateMany({}, {$pull: {roles: (req.body._id)}});
const ret = await DB.Role.findOneAndUpdate({ _id: req.body._id }, { del: 1 }); const ret = await DB.Role.findOneAndUpdate({ _id: req.body._id }, { del: 1 });
......
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