明树Git Lab

Commit e392c54c authored by zengfanpei's avatar zengfanpei

update

parent 43dcb978
......@@ -21,7 +21,7 @@ async function createDepart(req, res, next) {
if (req.body.parentId) {
let parentDepart = await departModule.findOne({ _id: req.body.parentId });
if (!(parentDepart && parentDepart._id)) {
res.sendError(errorMessage.resourceNotFound);
return res.sendError(errorMessage.resourceNotFound);
}
parentIds = parentDepart.parentIds || [];
parentIds.push(parentDepart._id);
......@@ -56,7 +56,7 @@ async function getDepartInfo(req, res, next) {
async function updateDepart(req, res, next) {
try {
if(!req.body._id) {
res.sendError(errorMessage.resourceNotFound)
return res.sendError(errorMessage.resourceNotFound)
}
let updateObj = {
...req.body,
......@@ -67,7 +67,7 @@ async function updateDepart(req, res, next) {
if (req.body.parentId) {
let parentDepart = await departModule.findOne({ _id: req.body.parentId });
if (!(parentDepart && parentDepart._id)) {
res.sendError(errorMessage.resourceNotFound);
return res.sendError(errorMessage.resourceNotFound);
}
parentIds = parentDepart.parentIds || [];
parentIds.push(parentDepart._id);
......
......@@ -15,7 +15,7 @@ async function createMenu(req, res, next) {
if (req.body.parentId) {
let parentDepart = await DB.Menu.findOne({ _id: req.body.parentId });
if (!(parentDepart && parentDepart._id)) {
res.sendError(errorMessage.resourceNotFound);
return res.sendError(errorMessage.resourceNotFound);
}
parentIds = parentDepart.parentIds || [];
parentIds.push(parentDepart._id);
......@@ -42,7 +42,7 @@ async function updateMenu(req, res, next) {
if (req.body.parentId) {
let parentDepart = await DB.Menu.findOne({ _id: req.body.parentId });
if (!(parentDepart && parentDepart._id)) {
res.sendError(errorMessage.resourceNotFound);
return res.sendError(errorMessage.resourceNotFound);
}
parentIds = parentDepart.parentIds || [];
parentIds.push(parentDepart._id);
......
......@@ -211,7 +211,7 @@ async function getAreaDistribution(req, res, next) {
// 跟前端约定 传递对应区域名称
let zonePre = await DB.Zone.findOne({ name: req.body.name, del: 0 });
if (!zonePre) {
res.sendError(errorMessage.resourceNotFound);
return res.sendError(errorMessage.resourceNotFound);
}
//往下取一层
let len = zonePre.parentIds && zonePre.parentIds.length || 0;
......
......@@ -42,7 +42,7 @@ async function login(req, res, next) {
const { mobile, password } = req.body;
const user = await userModule.findUserByMobile(mobile);
if (!user) {
res.sendError(errorMessage.loginError);
return res.sendError(errorMessage.loginError);
}
const check = utils.checkUserPassword({
reqPw: password,
......@@ -50,7 +50,7 @@ async function login(req, res, next) {
userPw: user.password,
});
if (!check) {
res.sendError(errorMessage.loginError)
return res.sendError(errorMessage.loginError)
}
// 生成一个串 返回前端
let token = crypto.randomUUID();
......@@ -196,7 +196,7 @@ async function getRole(req, res, next) {
let ret = await DB.Role.findOne({ _id: req.body._id }).lean().exec();
if (!(ret && ret._id)) {
res.sendError(errorMessage.resourceNotFound);
return res.sendError(errorMessage.resourceNotFound);
}
// /**
// * 将role拥有的menus、buttons标记(permission)到菜单树结构中 返回给前端
......@@ -332,7 +332,7 @@ async function updateRole(req, res, next) {
async function deleteRole(req, res, next) {
try {
if(!req.body._id) {
res.sendError(errorMessage.resourceNotFound)
return res.sendError(errorMessage.resourceNotFound)
}
// 角色删除 将用户中的角色去掉。$pull 从数组中删除一个指定元素
await DB.User.updateMany({}, {$pull: {roles: (req.body._id)}});
......
......@@ -17,7 +17,7 @@ async function create(req, res, next) {
if (req.body.parentId) {
let parentDepart = await DB.Zone.findOne({ _id: req.body.parentId });
if (!(parentDepart && parentDepart._id)) {
res.sendError(errorMessage.resourceNotFound);
return res.sendError(errorMessage.resourceNotFound);
}
parentIds = parentDepart.parentIds || [];
parentIds.push(parentDepart._id);
......@@ -43,7 +43,7 @@ async function update(req, res, next) {
if (req.body.parentId) {
let parentDepart = await DB.Zone.findOne({ _id: req.body.parentId });
if (!(parentDepart && parentDepart._id)) {
res.sendError(errorMessage.resourceNotFound);
return res.sendError(errorMessage.resourceNotFound);
}
parentIds = parentDepart.parentIds || [];
parentIds.push(parentDepart._id);
......
......@@ -11,7 +11,10 @@ async function findUserByMobile(mobile) {
if (!mobile) {
return null;
}
const user = await DB.User.findOne({ mobile }).populate({ path: "roles depart avatar" }).lean();
const user = await DB.User.findOne({ mobile }).populate({path: "roles", select: "name key", match: {del: 0}})
.populate({path: "depart", select: "name", match: {del: 0}})
.populate({path: "avatar"})
.lean().exec();//{ path: "roles depart avatar" }
return user;
}
......
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