feat add questions module and admin routes
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { Role } from '@/common/enums/roles.enum';
|
||||
import { Roles } from '@/modules/auth/decorators/roles.decorator';
|
||||
import { CreateQuestionDTO } from '@/modules/questions/dtos/create-question.dto';
|
||||
import { FindQuestionsDTO } from '@/modules/questions/dtos/find-questions.dto';
|
||||
import { UpdateQuestionDTO } from '@/modules/questions/dtos/update-question.dto';
|
||||
import { QuestionsService } from '@/modules/questions/providers/questions.service';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
|
||||
@Controller('admin/questions')
|
||||
@Roles(Role.SUPERUSER, Role.ADMIN)
|
||||
export class AdminQuestionsController {
|
||||
constructor(
|
||||
/**
|
||||
* Inject Questions Service Provider
|
||||
*/
|
||||
private readonly questionsService: QuestionsService,
|
||||
) {}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
public async getQuestionById(@Param('id', ParseIntPipe) id: number) {
|
||||
return await this.questionsService.findOneForAdmin(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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user