Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
34 changes: 31 additions & 3 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,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,
Expand Down Expand Up @@ -758,6 +785,7 @@ export class FlowService {
projectStars,
allProjects,
);
// console.log('real progress:', realProgress);

const progress = Math.min(1, realProgress * 3);

Expand Down Expand Up @@ -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(
Expand Down