2022-08-08 16:47:28 +00:00
|
|
|
|
|
|
|
import { Op, Sequelize } from "sequelize";
|
|
|
|
import Queue from "../../models/Queue";
|
2022-05-06 22:49:45 +00:00
|
|
|
import User from "../../models/User";
|
2022-08-08 16:47:28 +00:00
|
|
|
import UserQueue from "../../models/UserQueue";
|
2022-05-06 22:49:45 +00:00
|
|
|
|
|
|
|
interface Request {
|
2022-08-08 16:47:28 +00:00
|
|
|
userId?: string | number;
|
|
|
|
profile?: string;
|
|
|
|
}
|
|
|
|
|
2022-05-06 22:49:45 +00:00
|
|
|
|
2022-08-08 16:47:28 +00:00
|
|
|
const ListUser = async ({ profile, userId }: Request): Promise<User[]> => {
|
2022-05-06 22:49:45 +00:00
|
|
|
|
2022-08-08 16:47:28 +00:00
|
|
|
let where_clause = {}
|
2022-05-06 22:49:45 +00:00
|
|
|
|
2022-08-08 16:47:28 +00:00
|
|
|
if (userId && profile) {
|
|
|
|
where_clause = {
|
|
|
|
[Op.and]: [
|
|
|
|
{ userId: userId },
|
|
|
|
{ profile: profile }
|
|
|
|
]
|
2022-05-06 22:49:45 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
}
|
|
|
|
else if (userId) {
|
|
|
|
where_clause = {
|
|
|
|
[Op.and]: [
|
|
|
|
{ userId: userId },
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (profile) {
|
|
|
|
where_clause = {
|
|
|
|
profile: profile
|
2022-05-06 22:49:45 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
}
|
2022-05-06 22:49:45 +00:00
|
|
|
|
2022-08-08 16:47:28 +00:00
|
|
|
|
|
|
|
const users = await User.findAll({
|
2022-05-06 22:49:45 +00:00
|
|
|
where: where_clause,
|
2022-08-08 16:47:28 +00:00
|
|
|
raw: true,
|
2022-05-06 22:49:45 +00:00
|
|
|
attributes: ['id', 'name', 'email'],
|
|
|
|
|
|
|
|
|
2022-08-08 16:47:28 +00:00
|
|
|
// include: [
|
|
|
|
// {
|
|
|
|
// model: UserQueue,
|
|
|
|
// separate: true,
|
|
|
|
|
|
|
|
// attributes: ['id',],
|
|
|
|
|
|
|
|
// order: [
|
|
|
|
// ['createdAt', 'ASC']
|
|
|
|
// ]
|
|
|
|
// },
|
|
|
|
// ],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
order: [["id", "ASC"]],
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2022-05-06 22:49:45 +00:00
|
|
|
return users;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ListUser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|