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..d7d256a 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,14 +592,15 @@ 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(el.projectId, userId), })), ); - 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) => {