feat(backend) alteração no metodo que retorna usuarios para retornar por profile

adriano 2023-10-23 09:10:44 -03:00
parent df9d468700
commit b15fd47c8b
1 changed files with 30 additions and 42 deletions

View File

@ -1,4 +1,3 @@
import { Op, Sequelize } from "sequelize"; import { Op, Sequelize } from "sequelize";
import Queue from "../../models/Queue"; import Queue from "../../models/Queue";
import User from "../../models/User"; import User from "../../models/User";
@ -7,65 +6,54 @@ import UserQueue from "../../models/UserQueue";
interface Request { interface Request {
userId?: string | number; userId?: string | number;
profile?: string; profile?: string;
raw?: boolean;
} }
const ListUser = async ({ profile, userId, raw }: Request): Promise<User[]> => {
const ListUser = async ({ profile, userId }: Request): Promise<User[]> => { let where_clause = {};
let where_clause = {}
if (userId && profile) { if (userId && profile) {
where_clause = { where_clause = {
[Op.and]: [ [Op.and]: [{ userId: userId }, { profile: profile }]
{ userId: userId }, };
{ profile: profile } } else if (userId) {
]
}
}
else if (userId) {
where_clause = { where_clause = {
[Op.and]: [ [Op.and]: [{ userId: userId }]
{ userId: userId }, };
] } else if (profile) {
}
}
else if (profile) {
where_clause = { where_clause = {
profile: profile profile: profile
} };
} }
const queryOptions: any = {
const users = await User.findAll({
where: where_clause, where: where_clause,
raw: true, raw,
attributes: ['id', 'name', 'email'], attributes: ["id", "name", "email"],
order: [["id", "ASC"]]
};
// include: [ if (!raw) {
// { queryOptions.include = [
// model: UserQueue, { model: Queue, as: "queues", attributes: ["id", "name", "color"] }
// separate: true, ];
}
// attributes: ['id',], const users = await User.findAll(queryOptions);
// order: [ // const users = await User.findAll({
// ['createdAt', 'ASC'] // where: where_clause,
// ] // raw,
// }, // attributes: ['id', 'name', 'email'],
// ],
// include: [
// { model: Queue, as: "queues", attributes: ["id", "name", "color"] }
// ],
// order: [["id", "ASC"]],
order: [["id", "ASC"]], // })
})
return users; return users;
}; };
export default ListUser; export default ListUser;