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";
|
2024-01-29 17:17:42 +00:00
|
|
|
import { List } from "whatsapp-web.js"
|
2022-05-06 22:49:45 +00:00
|
|
|
|
|
|
|
interface Request {
|
2022-08-08 16:47:28 +00:00
|
|
|
userId?: string | number;
|
|
|
|
profile?: string;
|
2024-01-29 17:17:42 +00:00
|
|
|
profiles?: Array<string>;
|
2024-01-29 11:48:20 +00:00
|
|
|
raw?: boolean;
|
2024-01-29 17:17:42 +00:00
|
|
|
userIds?: string | number;
|
2022-08-08 16:47:28 +00:00
|
|
|
}
|
|
|
|
|
2024-01-29 17:17:42 +00:00
|
|
|
const ListUser = async ({ profile, userId, raw, userIds, profiles }: Request): Promise<User[]> => {
|
2024-01-29 11:48:20 +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 = {
|
2024-01-29 11:48:20 +00:00
|
|
|
[Op.and]: [{ userId: userId }, { profile: profile }]
|
|
|
|
};
|
|
|
|
} else if (userId) {
|
2022-08-08 16:47:28 +00:00
|
|
|
where_clause = {
|
2024-01-29 11:48:20 +00:00
|
|
|
[Op.and]: [{ userId: userId }]
|
|
|
|
};
|
|
|
|
} else if (profile) {
|
2022-08-08 16:47:28 +00:00
|
|
|
where_clause = {
|
|
|
|
profile: profile
|
2024-01-29 11:48:20 +00:00
|
|
|
};
|
|
|
|
} else if (userIds) {
|
|
|
|
where_clause = {
|
|
|
|
id: { [Op.in]: userIds }
|
|
|
|
};
|
2024-01-29 17:17:42 +00:00
|
|
|
} else if (profiles) {
|
|
|
|
where_clause = {
|
|
|
|
profile: { [Op.in]: profiles }
|
|
|
|
};
|
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,
|
2024-01-29 11:48:20 +00:00
|
|
|
raw,
|
2024-02-01 20:46:23 +00:00
|
|
|
attributes: ["id", "name", "email", "positionCompany"],
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
include: [
|
|
|
|
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] }
|
2024-01-29 17:17:42 +00:00
|
|
|
],
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2024-01-29 17:17:42 +00:00
|
|
|
order: [["id", "ASC"]],
|
|
|
|
group: ["User.id"]
|
2024-01-29 11:48:20 +00:00
|
|
|
});
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-05-06 22:49:45 +00:00
|
|
|
return users;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ListUser;
|