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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user