diff --git a/src/flow/flow.controller.ts b/src/flow/flow.controller.ts index 845d2ce..13d2548 100644 --- a/src/flow/flow.controller.ts +++ b/src/flow/flow.controller.ts @@ -172,6 +172,21 @@ export class FlowController { return 'Success'; } + @UseGuards(AuthGuard) + @ApiOperation({ + summary: 'Used to unmark a project as Conflict of Interest', + }) + @ApiBody({ + type: SetCoIDto, + description: 'Project id', + }) + @UseGuards(AuthGuard) + @Post('/unmark-coI') + async unmarkCoI(@Req() { userId }: AuthedReq, @Body() { pid }: SetCoIDto) { + await this.flowService.unsetCoi(userId, pid); + return 'Success'; + } + @UseGuards(AuthGuard) @ApiOperation({ summary: 'Used for a pairwise vote between two projects', diff --git a/src/flow/flow.service.ts b/src/flow/flow.service.ts index 413dab6..e112e55 100644 --- a/src/flow/flow.service.ts +++ b/src/flow/flow.service.ts @@ -260,6 +260,30 @@ export class FlowService { }); }; + unsetCoi = async (userId: number, projectId: number) => { + await this.prismaService.projectCoI.delete({ + where: { + userId_projectId: { + projectId, + userId, + }, + }, + }); + }; + + isCoi = async (userId: number, projectId: number) => { + const res = await this.prismaService.projectCoI.findUnique({ + where: { + userId_projectId: { + projectId, + userId, + }, + }, + }); + + return !!res; + }; + setRating = async ( projectId: number, userId: number, @@ -568,17 +592,20 @@ export class FlowService { include: { project: true }, }); - const withStars = await Promise.all( + const withMoreFields = await Promise.all( ranking.map(async (el) => ({ ...el, stars: await this.getProjectStars(el.projectId, userId), + coi: await this.isCoi(userId, el.projectId), })), ); - return withStars.sort((a, b) => b.share - a.share); + return withMoreFields.sort((a, b) => b.share - a.share); }; undo = async (userId: number, parentCollection: number | null) => { + // TODO: Check if a colleciton is still wip and not finished + const lastVote = await this.prismaService.vote.findFirst({ where: { userId, @@ -758,6 +785,7 @@ export class FlowService { projectStars, allProjects, ); + // console.log('real progress:', realProgress); const progress = Math.min(1, realProgress * 3); @@ -808,7 +836,7 @@ export class FlowService { new Set(allProjects.map((item) => item.implicitCategory)), ).map((cat, index) => ({ name: cat, priority: index * 2 })); - console.log(shuffleArraySeeded(implicitCategoryPriorities, userId)); + // console.log(shuffleArraySeeded(implicitCategoryPriorities, userId)); const getImplicitCatScore = (cat: string) => shuffleArraySeeded(implicitCategoryPriorities, userId).find(