54 lines
889 B
TypeScript
54 lines
889 B
TypeScript
|
|
||
|
import { Op, Sequelize } from "sequelize";
|
||
|
import User from "../../models/User";
|
||
|
|
||
|
interface Request {
|
||
|
userId?: string | number;
|
||
|
profile?: string;
|
||
|
}
|
||
|
|
||
|
|
||
|
const ListUser = async ({profile, userId}: Request): Promise<User[]> => {
|
||
|
|
||
|
let where_clause = {}
|
||
|
|
||
|
if(userId && profile){
|
||
|
where_clause = {
|
||
|
[Op.and]: [
|
||
|
{userId: userId},
|
||
|
{profile: profile}
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
else if(userId){
|
||
|
where_clause = {
|
||
|
[Op.and]: [
|
||
|
{userId: userId},
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
else if(profile){
|
||
|
where_clause = {
|
||
|
profile: profile
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
const users = await User.findAll({
|
||
|
where: where_clause,
|
||
|
raw:true,
|
||
|
attributes: ['id', 'name', 'email'],
|
||
|
|
||
|
order: [["id", "ASC"]],
|
||
|
})
|
||
|
|
||
|
|
||
|
return users;
|
||
|
};
|
||
|
|
||
|
export default ListUser;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|