明树Git Lab

Commit a7cb8cb4 authored by zfp1's avatar zfp1

update

parent 6482a79e
...@@ -34,7 +34,7 @@ async function login(req, res, next) { ...@@ -34,7 +34,7 @@ async function login(req, res, next) {
include: [{ include: [{
model: DB.Role, model: DB.Role,
as: 'roles', as: 'roles',
where: { del: 0 }, // where: { del: 0 },
attributes: ["id", "name"], attributes: ["id", "name"],
through: { attributes: [] }, through: { attributes: [] },
include: [{ include: [{
...@@ -44,10 +44,11 @@ async function login(req, res, next) { ...@@ -44,10 +44,11 @@ async function login(req, res, next) {
// attributes: ['id', 'name', 'parentId'], // attributes: ['id', 'name', 'parentId'],
through: { attributes: [] }, through: { attributes: [] },
}] }]
}, { },
{
model: DB.Depart, model: DB.Depart,
as: 'departs', as: 'departs',
where: { del: 0 }, // where: { del: 0 }, 当刚注册的用户 没有分配角色、部门时加上条件会查不到
attributes: ["id", "name"], attributes: ["id", "name"],
through: { attributes: [] }, through: { attributes: [] },
} }
...@@ -82,7 +83,7 @@ async function login(req, res, next) { ...@@ -82,7 +83,7 @@ async function login(req, res, next) {
delete element.menus; delete element.menus;
newRoles.push(element); newRoles.push(element);
} }
user.roles = roles || []; user.roles = newRoles || [];
user.menus = utils.buildTree(menus); user.menus = utils.buildTree(menus);
return res.sendData(user); return res.sendData(user);
} catch (error) { } catch (error) {
...@@ -176,13 +177,13 @@ async function updateUser(req, res, next) { ...@@ -176,13 +177,13 @@ async function updateUser(req, res, next) {
} }
if (body.departs && body.departs.length) { if (body.departs && body.departs.length) {
//跟现有情况对比 确定增删关系 //跟现有情况对比 确定增删关系
const departIds = body.departs.map(o => {return o && o.id || o}); const departIds = body.departs.map(o => { return o && o.id || o });
await userModule.setUserDepart(user.id, departIds, user.departs); await userModule.setUserDepart(user.id, departIds, user.departs);
delete body.departs; delete body.departs;
} }
if (body.roles && body.roles.length) { if (body.roles && body.roles.length) {
//跟现有情况对比 确定增删关系 //跟现有情况对比 确定增删关系
const roleIds = body.roles.map(o => {return o && o.id || o}); const roleIds = body.roles.map(o => { return o && o.id || o });
await userModule.setUserRole(user.id, roleIds, user.roles); await userModule.setUserRole(user.id, roleIds, user.roles);
delete body.roles; delete body.roles;
} }
......
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