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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
DELETE http://localhost:3000/admin/questions/11
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxNDQ2Njg2LCJleHAiOjE3ODE0NTAyODYsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.3L6jYtNwlcLr9A9lJo6pOiTIi2rHKIqSXWphH4mgbSU
|
||||
@@ -0,0 +1,5 @@
|
||||
GET http://localhost:3000/admin/questions
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxMTkxMjMxLCJleHAiOjE3ODExOTQ4MzEsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.6WsJHzWWQSCEzPklyHePOmXQhfH4pfIIUZA3c5Z3yFI
|
||||
|
||||
GET http://localhost:3000/admin/questions/1
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxMTkxMjMxLCJleHAiOjE3ODExOTQ4MzEsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.6WsJHzWWQSCEzPklyHePOmXQhfH4pfIIUZA3c5Z3yFI
|
||||
@@ -0,0 +1,9 @@
|
||||
PATCH http://localhost:3000/admin/questions/1
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxNDIyMjkxLCJleHAiOjE3ODE0MjU4OTEsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.djDjd0v7UwfITA4Bh-PC5G830o9wu2CgRKRenwuJJ4E
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"metadata": {
|
||||
"allowOther": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
POST http://localhost:3000/admin/questions
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxMTYyMTUxLCJleHAiOjE3ODExNjU3NTEsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.Z4oBnTrD-wTTlcThCSGslRco_HJhnQJpg-reGubTUec
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"test": 4,
|
||||
"content": "سوال پنجم",
|
||||
"order": 4,
|
||||
"required": true,
|
||||
"type": "numeric",
|
||||
"metadata": { "min": 1, "max": 100 }
|
||||
}
|
||||
Reference in New Issue
Block a user