import { Role } from '@/common/enums/roles.enum'; import { Roles } from '@/modules/auth/decorators/roles.decorator'; import { CreateQuestionRangeRuleDTO } from '@/modules/questions/dtos/create-question-range-rule.dto'; import { CreateQuestionDTO } from '@/modules/questions/dtos/create-question.dto'; import { FindQuestionRangeRuleDTO } from '@/modules/questions/dtos/find-question-range-rule.dto'; import { FindQuestionsDTO } from '@/modules/questions/dtos/find-questions.dto'; import { UpdateQuestionRangeRuleDTO } from '@/modules/questions/dtos/update-question-range-rule.dto'; import { UpdateQuestionDTO } from '@/modules/questions/dtos/update-question.dto'; import { QuestionRangeRuleService } from '@/modules/questions/providers/question-range-rule.service'; import { QuestionsService } from '@/modules/questions/providers/questions.service'; import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, ParseIntPipe, Patch, Post, Query, } from '@nestjs/common'; import { Throttle } from '@nestjs/throttler'; @Controller('admin/questions') @Roles(Role.SUPERUSER, Role.ADMIN) @Throttle({ admin: {} }) export class AdminQuestionsController { constructor( /** * Inject Questions Service Provider */ private readonly questionsService: QuestionsService, /** * Inject Questions Range Rules Service */ private readonly questionRangeRulesService: QuestionRangeRuleService, ) {} @Post() public async createQuestion(@Body() createQuestionDto: CreateQuestionDTO) { return await this.questionsService.createOne(createQuestionDto); } @Get() public async getAllQuestions(@Query() query: FindQuestionsDTO) { return await this.questionsService.findAllForAdmin(query); } @Post('range-rules') public async createQuestionRangeRule( @Body() createQuestionRangeRuleDto: CreateQuestionRangeRuleDTO, ) { return await this.questionRangeRulesService.createOne( createQuestionRangeRuleDto, ); } @Get('range-rules') public async getAllQuestionRangeRules( @Query() query: FindQuestionRangeRuleDTO, ) { return await this.questionRangeRulesService.findAllForAdmin(query); } @Get('range-rules/:id') public async getQuestionRangeRuleById(@Param('id', ParseIntPipe) id: number) { return await this.questionRangeRulesService.findOneForAdmin(id); } @Patch('range-rules/:id') public async updateQuestionRangeRule( @Param('id', ParseIntPipe) id: number, @Body() updateQuestionRangeRuleDto: UpdateQuestionRangeRuleDTO, ) { return await this.questionRangeRulesService.updateOne( id, updateQuestionRangeRuleDto, ); } @Delete('range-rules/:id') @HttpCode(HttpStatus.NO_CONTENT) public async deleteQuestionRangeRule(@Param('id', ParseIntPipe) id: number) { return await this.questionRangeRulesService.deleteOne(id); } @Get(':id') public async getQuestionById(@Param('id', ParseIntPipe) id: number) { return await this.questionsService.findOneByIdForAdmin(id); } @Patch(':id') public async updateQuestionById( @Param('id', ParseIntPipe) id: number, @Body() updateQuestionDto: UpdateQuestionDTO, ) { return await this.questionsService.updateOne(id, updateQuestionDto); } @Delete(':id') @HttpCode(HttpStatus.NO_CONTENT) public async deleteQuestionById(@Param('id', ParseIntPipe) id: number) { return await this.questionsService.deleteOne(id); } }