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