明树Git Lab

Commit 300455a8 authored by zhangqi's avatar zhangqi

根据departId检索用户信息

parent 62a1612d
...@@ -125,35 +125,40 @@ async function getDepart(req, res, next) { ...@@ -125,35 +125,40 @@ async function getDepart(req, res, next) {
} }
} }
async function getDepartUsers(req, res, next) { async function getDepartUsers(req, res, next) {
try { try {
let page = req.body.page || 1; let page = req.body.page || 1;
let limit = req.body.pageSize || 10; let limit = req.body.pageSize || 10;
let offset = (page - 1) * limit; let offset = (page - 1) * limit;
let search = {}
search = {
where: {
del: 0
},
limit,
offset,
distinct: true,
col: 'id',
include: [
{ model: DB.Role, as: 'roles', through: { attributes: [] } },
{ model: DB.Depart, as: 'departs', through: { attributes: [] } },
{ model: DB.Position, as: 'positions', through: { attributes: [] } }
]
};
if (!req.body.departId) { if (!req.body.departId) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} else {
search.include[1].where = { id: req.body.departId };
} }
const ret = await DB.User.findAndCountAll({ if (req.body.name) {
where: { del: 0 }, search.where.name = { [Op.like]: `%${req.body.name}%` };
limit, }
offset, if (req.body.mobile) {
include: [ search.where.mobile = { [Op.like]: `%${req.body.mobile}%` };
{ }
model: DB.Role, console.log("search",search)
as: 'roles', const ret = await DB.User.findAndCountAll(search);
through: { attributes: [] },
}, {
model: DB.Depart,
as: 'departs',
through: { attributes: [] },
}, {
model: DB.Position,
as: 'positions',
through: { attributes: [] },
}
]
});
return res.sendData(ret); return res.sendData(ret);
} catch (error) { } catch (error) {
next(error); next(error);
......
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