feat: add choices entity admin crud
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 { CreateChoiceDTO } from '@/modules/questions/dtos/create-choice.dto';
|
||||
import { FindChoicesDTO } from '@/modules/questions/dtos/find-choices.dto';
|
||||
import { UpdateChoiceDTO } from '@/modules/questions/dtos/update-choice.dto';
|
||||
import { ChoicesService } from '@/modules/questions/providers/choices.service';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
|
||||
@Controller('admin/choices')
|
||||
@Roles(Role.SUPERUSER, Role.ADMIN)
|
||||
export class AdminChoicesController {
|
||||
constructor(
|
||||
/**
|
||||
* Inject Choices Service
|
||||
*/
|
||||
private readonly choicesService: ChoicesService,
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
public async createChoice(@Body() createChoiceDto: CreateChoiceDTO) {
|
||||
return await this.choicesService.createOne(createChoiceDto);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
public async updateChoice(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Body() updateChoiceDto: UpdateChoiceDTO,
|
||||
) {
|
||||
return await this.choicesService.updateOne(id, updateChoiceDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
public async deleteChoice(@Param('id', ParseIntPipe) id: number) {
|
||||
return await this.choicesService.deleteOne(id);
|
||||
}
|
||||
|
||||
@Get()
|
||||
public async getAllChoices(@Query() query: FindChoicesDTO) {
|
||||
return await this.choicesService.findAllForAdmin(query);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
public async getChoiceById(@Param('id', ParseIntPipe) id: number) {
|
||||
return await this.choicesService.findOneForAdmin(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
GET http://localhost:3000/admin/choices/
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxNjgxNzAzLCJleHAiOjE3ODE2ODUzMDMsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.WD14d4CqEiM1EkNFf9ky1B-i32RmoVGbYYXaYJs4UC0
|
||||
|
||||
GET http://localhost:3000/admin/choices/1
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxNjgxNzAzLCJleHAiOjE3ODE2ODUzMDMsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.WD14d4CqEiM1EkNFf9ky1B-i32RmoVGbYYXaYJs4UC0
|
||||
@@ -0,0 +1,2 @@
|
||||
DELETE http://localhost:3000/admin/choices/6
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxNTg0MjY1LCJleHAiOjE3ODE1ODc4NjUsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.lV1U9uXQTAJmCamZfCDcDpITfIZs4QlVd9Fcjsr0BrA
|
||||
@@ -0,0 +1,7 @@
|
||||
PATCH http://localhost:3000/admin/choices/1
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxNTMwNTI1LCJleHAiOjE3ODE1MzQxMjUsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.C_Ol-dkX7mouofKqbc-VxtP4qF6WiCPmlpKXuq85DiQ
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"question": 4
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
POST http://localhost:3000/admin/choices
|
||||
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEwLCJwaG9uZSI6IjA5MzMzMDI2MzYzIiwiaWF0IjoxNzgxNTg0MjY1LCJleHAiOjE3ODE1ODc4NjUsImF1ZCI6ImxvY2FsaG9zdCIsImlzcyI6ImxvY2FsaG9zdCJ9.lV1U9uXQTAJmCamZfCDcDpITfIZs4QlVd9Fcjsr0BrA
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"question": 4,
|
||||
"text": "Option 2",
|
||||
"value": 2,
|
||||
"order": 2
|
||||
}
|
||||
Reference in New Issue
Block a user