Skip to content

Commit

Permalink
Merge pull request #360 from bounswe/be-313/create_approve_endpoint
Browse files Browse the repository at this point in the history
be-313: Create approve disapprove endpoint
  • Loading branch information
BatuhanIlhan authored Nov 21, 2023
2 parents 20f981d + ea805f9 commit 60da504
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
12 changes: 12 additions & 0 deletions app/backend/src/moderator/dto/approve.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApiProperty } from "@nestjs/swagger";
import { IsBoolean, IsNotEmpty } from "class-validator";

export class ApproveDTO {
@ApiProperty({
example: 'false',
})
@IsBoolean()
@IsNotEmpty()
approveStatus: boolean;

}
7 changes: 7 additions & 0 deletions app/backend/src/moderator/moderator.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CreateModeratorDto } from './dto/create_moderator.dto';
import { VerifyModeratorDto } from './dto/verify_moderator.dto';
import { ModeratorGuard } from './guards/moderator.guard';
import { VerificationGuard } from './guards/verification.guard';
import { ApproveDTO } from './dto/approve.dto';

@ApiBearerAuth()
@Controller('moderator')
Expand Down Expand Up @@ -50,4 +51,10 @@ export class ModeratorController {
remove(@Param('id') id: string) {
return this.moderatorService.removeById(id);
}

@UseGuards(ModeratorGuard, VerificationGuard)
@Post('approve/:id')
approve(@Param('id') id : string, @Body() approveDto: ApproveDTO){
return this.moderatorService.approve_disapprove(id,approveDto);
}
}
10 changes: 9 additions & 1 deletion app/backend/src/moderator/moderator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MailerService } from '@nestjs-modules/mailer';
import { JwtService } from '@nestjs/jwt';
import { VerifyModeratorDto } from './dto/verify_moderator.dto';
import { Poll } from '../poll/entities/poll.entity';
import { ApproveDTO } from './dto/approve.dto';

@Injectable()
export class ModeratorService {
Expand Down Expand Up @@ -113,7 +114,7 @@ export class ModeratorService {
public async fetchUnapprovedPolls(): Promise<Poll[]> {
return await this.pollRepository.find({
where: {
is_approved_by_moderator: false,
approveStatus: false,
},
relations: ['options', 'tags', 'creator'],
});
Expand Down Expand Up @@ -148,4 +149,11 @@ export class ModeratorService {
public generateCode(): number {
return Math.floor(Math.random() * 9000 + 1000);
}


public async approve_disapprove(pollId: string, approveDto : ApproveDTO): Promise<void>{
await this.pollRepository.update(pollId, approveDto)
}


}
2 changes: 1 addition & 1 deletion app/backend/src/poll/entities/poll.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Poll {
//report_list: Array<any>;

@Column({ default: false })
is_approved_by_moderator: boolean;
approveStatus: boolean;

@Column({ default: false })
is_settled: boolean;
Expand Down

0 comments on commit 60da504

Please sign in to comment.