Skip to content

Commit

Permalink
Merge pull request #665 from bounswe/be-625/vote-infos-on-fetch-polls
Browse files Browse the repository at this point in the history
Be 625/vote infos on fetch polls
  • Loading branch information
Alputer authored Dec 22, 2023
2 parents 76b5023 + 65cf532 commit 9e375ef
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 72 deletions.
6 changes: 3 additions & 3 deletions app/backend/src/poll/entities/poll.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Poll {
options: Relation<Option[]>;

@Column({ nullable: true })
outcome: string
outcome: string;

@Column({ nullable: true })
outcome_source: string;
Expand All @@ -61,7 +61,7 @@ export class Poll {
@OneToMany(() => Comment, (comment) => comment.poll)
comments: Relation<Comment[]>;

@OneToMany(() => Vote, (vote) => vote.poll)
@OneToMany(() => Vote, (vote) => vote.poll, { cascade: true })
votes: Relation<Vote[]>;

@Column({ default: 0 })
Expand All @@ -83,6 +83,6 @@ export class Poll {
@Column({ nullable: true })
poll_request_rejection_feedback: string;

@Column("simple-array",{ nullable: true })
@Column('simple-array', { nullable: true })
image_urls: string[];
}
65 changes: 49 additions & 16 deletions app/backend/src/poll/poll.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class PollController {
public async updateTags(
@Param('id', ParseUUIDPipe) id: string,
@Body() updateTagsDto: UpdateTagsDto,
): Promise<void> {
): Promise<Poll> {
return await this.pollService.updatePollTags(id, updateTagsDto);
}

Expand All @@ -152,6 +152,7 @@ export class PollController {
@ApiQuery({ name: 'creatorId', required: false })
@ApiQuery({ name: 'approveStatus', required: false })
@ApiQuery({ name: 'likedById', required: false })
@ApiQuery({ name: 'votedById', required: false })
@ApiQuery({ name: 'followedById', required: false })
@ApiQuery({ name: 'sort', required: false })
@ApiQuery({ name: 'tags', required: false })
Expand All @@ -173,6 +174,8 @@ export class PollController {
approveStatus?: string,
@Query('likedById', new ParseUUIDPipe({ optional: true }))
likedById?: string,
@Query('votedById', new ParseUUIDPipe({ optional: true }))
votedById?: string,
@Query('followedById', new ParseUUIDPipe({ optional: true }))
followedById?: string,
@Query('sort')
Expand All @@ -185,6 +188,7 @@ export class PollController {
creatorId,
approveStatus,
likedById,
votedById,
followedById,
sortString,
tags,
Expand All @@ -210,6 +214,7 @@ export class PollController {
creatorId,
approveStatus: null,
likedById: null,
votedById: null,
followedById: null,
sortString: null,
tags: null,
Expand Down Expand Up @@ -260,13 +265,55 @@ export class PollController {
creatorId: null,
approveStatus: null,
likedById: userId,
votedById: null,
followedById: null,
sortString: null,
tags: null,
userId,
});
}

@UseGuards(AuthGuard, VerificationGuard)
@ApiResponse({
status: 200,
description: 'Polls are fetched successfully.',
type: [GetPollResponseDto],
})
@ApiResponse({
status: 500,
description: 'Internal server error, contact with backend team.',
})
@Get('voted-by-me')
public async findPollsIVoted(@Req() req: any): Promise<any> {
const userId = req.user.id;
return await this.pollService.findAll({
creatorId: null,
approveStatus: null,
likedById: null,
votedById: userId,
followedById: null,
sortString: null,
tags: null,
userId,
});
}

@UseGuards(AuthGuard, VerificationGuard)
@ApiResponse({
status: 200,
description: 'Polls are fetched successfully.',
type: [GetPollResponseDto],
})
@ApiResponse({
status: 500,
description: 'Internal server error, contact with backend team.',
})
@Get('not-voted-by-me')
public async findPollsIdidNoteVote(@Req() req: any): Promise<any> {
const userId = req.user.id;
return await this.pollService.findPollsUserdidNotVote(userId);
}

@UseGuards(AuthGuard, VerificationGuard)
@ApiResponse({
status: 200,
Expand All @@ -284,6 +331,7 @@ export class PollController {
creatorId: null,
approveStatus: null,
likedById: null,
votedById: null,
followedById: userId,
sortString: null,
tags: null,
Expand All @@ -310,21 +358,6 @@ export class PollController {
return await this.pollService.findPollById(pollId, userId);
}

@UseGuards(AuthGuard, VerificationGuard)
@ApiResponse({
status: 200,
description: 'Polls are removed successfully.',
})
@ApiResponse({ status: 404, description: 'Poll not found.' })
@ApiResponse({
status: 500,
description: 'Internal server error, contact with backend team.',
})
@Delete()
public async removeAll() {
return await this.pollService.removeAll();
}

@ApiResponse({ status: 200, description: 'Poll deleted successfully.' })
@ApiResponse({ status: 404, description: 'Poll not found.' })
@ApiResponse({
Expand Down
4 changes: 2 additions & 2 deletions app/backend/src/poll/poll.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { Vote } from '../vote/entities/vote.entity';
Comment,
Report,
Ranking,
Vote
Vote,
]),
TagModule,
],
Expand All @@ -56,7 +56,7 @@ import { Vote } from '../vote/entities/vote.entity';
TagService,
Pinecone,
GoogleGenerativeAIEmbeddings,
RankingService
RankingService,
],
exports: [PollService],
})
Expand Down
Loading

0 comments on commit 9e375ef

Please sign in to comment.