Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/projects #169

Merged
merged 9 commits into from
May 11, 2024
Merged
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions src/core/infra/repositories/project.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ async function findAll(): Promise<ProjectEntity[]> {
when status = 'Cancelled' then 7
when status = 'Accepted' then 8
when status = 'Done' then 9
else 10
when status = '-' then 10
else 11
sgarnica1 marked this conversation as resolved.
Show resolved Hide resolved
end asc
`;

console.log(data);
sgarnica1 marked this conversation as resolved.
Show resolved Hide resolved
if (!data) throw new NotFoundError(`${RESOURCE_NAME} error`);

return data.map(mapProjectEntityFromDbModel);
Expand All @@ -49,12 +52,21 @@ async function findAllByRole(role: SupportedRoles): Promise<ProjectEntity[]> {
let doneProjects: PrismaProjectsRes;
let res: Awaited<PrismaProjectsRes>;
if (role === SupportedRoles.ADMIN) {
projects = Prisma.project.findMany({ where: { NOT: { status: ProjectStatus.DONE } } });
projects = Prisma.project.findMany({
where: { NOT: { status: ProjectStatus.DONE } },
orderBy: { status: 'desc' },
});
doneProjects = Prisma.project.findMany({ where: { status: ProjectStatus.DONE } });
res = (await Promise.all([projects, doneProjects])).flat();
} else {
projects = Prisma.project.findMany({ where: { area: role, NOT: { status: ProjectStatus.DONE } } });
doneProjects = Prisma.project.findMany({ where: { status: ProjectStatus.DONE, area: role } });
projects = Prisma.project.findMany({
where: { area: role, NOT: { status: ProjectStatus.DONE } },
orderBy: { status: 'desc' },
});
doneProjects = Prisma.project.findMany({
where: { status: ProjectStatus.DONE, area: role },
orderBy: { status: 'desc' },
});
sgarnica1 marked this conversation as resolved.
Show resolved Hide resolved
res = (await Promise.all([projects, doneProjects])).flat();
}
if (!res) throw new NotFoundError(`${RESOURCE_NAME} error`);
Expand Down
Loading