明树Git Lab

Commit 300455a8 authored by zhangqi's avatar zhangqi

根据departId检索用户信息

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