Skip to content

Commit

Permalink
is settled query is added
Browse files Browse the repository at this point in the history
  • Loading branch information
batuhancetin committed Dec 18, 2023
1 parent 469aec0 commit 7d3b21b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/backend/src/moderator/moderator.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {
Delete,
Get,
Param,
ParseIntPipe,
Post,
Put,
Query,
UseGuards,
} from '@nestjs/common';
import { ModeratorService } from './moderator.service';
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
import { CreateModeratorDto } from './dto/create_moderator.dto';
import { VerifyModeratorDto } from './dto/verify_moderator.dto';
import { ModeratorGuard } from './guards/moderator.guard';
Expand All @@ -21,6 +23,7 @@ import { LoginResponseDto } from './dto/responses/login-response.dto';
import { GetModeratorResponseDto } from './dto/responses/get-moderator-response.dto';
import { GetPollResponseDto } from '../poll/dto/responses/get-poll-response.dto';
import { GetReportResponseDto } from '../user/dto/responses/get-report.response.dto';
import { Settle } from '../poll/enums/settle.enum';

@ApiBearerAuth()
@Controller('moderator')
Expand Down Expand Up @@ -98,6 +101,16 @@ export class ModeratorController {
public async fetchUnapprovedPolls(): Promise<GetPollResponseDto[]> {
return await this.moderatorService.fetchUnapprovedPolls();
}

@ApiQuery({ name: 'is_settled', required: false, description: '0: ACTIVE, 1: PENDING, 2: SETTLED, 3: CANCELLED' })
@UseGuards(ModeratorGuard, VerificationModeratorGuard)
@Get('polls/query')
public async fetchQueryPolls(
@Query('is_settled', new ParseIntPipe({ optional: true }))
is_settled?: Settle,
): Promise<GetPollResponseDto[]> {
return await this.moderatorService.fetchQueryPolls(is_settled);
}

@UseGuards(ModeratorGuard, VerificationModeratorGuard)
@Get('reports')
Expand Down
13 changes: 13 additions & 0 deletions app/backend/src/moderator/moderator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ApproveDTO } from './dto/approve.dto';
import { LoginModeratorDto } from './dto/login-moderator.dto';
import { Report } from '../user/entities/report.entity';
import { User } from '../user/entities/user.entity';
import { Settle } from '../poll/enums/settle.enum';

@Injectable()
export class ModeratorService {
Expand Down Expand Up @@ -235,4 +236,16 @@ export class ModeratorService {
resolved_date: new Date(),
});
}

public async fetchQueryPolls(is_settled: Settle): Promise<any> {
return await this.pollRepository.find({
where: {
is_settled: is_settled,
},
relations: ['options', 'tags', 'creator'],
order: {
creation_date: 'ASC',
},
});
}
}

0 comments on commit 7d3b21b

Please sign in to comment.