Skip to content

Commit

Permalink
Add needed coi endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahdigh committed Nov 12, 2024
1 parent 426a28b commit 49ed095
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/flow/flow.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
29 changes: 27 additions & 2 deletions src/flow/flow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 49ed095

Please sign in to comment.