Skip to content

Commit

Permalink
fix: fetchUsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Luana-ns committed Feb 1, 2024
1 parent 5310e4e commit 82cf3cd
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/dao/user.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,26 @@ class UserDAO {
pageSize = 10
) {
const skip = (page - 1) * pageSize;
const where = {
OR: [],
};
if (filter.email) {
where.OR.push({ email: { contains: filter.email } });
}
if (filter.username) {
where.OR.push({ username: { contains: filter.username } });
}
if (where.OR.length === 0) {
delete where.OR;
const where: Prisma.UserWhereInput = {};

if (filter.email || filter.username) {
where.OR = [];

if (filter.email) {
where.OR?.push({ email: { contains: filter.email } });
}
if (filter.username) {
where.OR?.push({ username: { contains: filter.username } });
}
if (where.OR?.length === 0) {
delete where.OR;
}
return prisma.user.findMany({
where: where as Prisma.UserWhereInput,
skip,
take: pageSize,
});
}
return prisma.user.findMany({
where,
skip,
take: pageSize,
});
}

async isOboardingFinished(username: string) {
Expand Down

0 comments on commit 82cf3cd

Please sign in to comment.