feat: add admin tests read and update endpoints
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
import { Role } from '@/common/enums/roles.enum';
|
||||
import { Roles } from '@/modules/auth/decorators/roles.decorator';
|
||||
import { CreateTestDTO } from '@/modules/tests/dtos/create-test.dto';
|
||||
import { UpdateTestDTO } from '@/modules/tests/dtos/update-test.dto';
|
||||
import { TestsService } from '@/modules/tests/providers/tests.service';
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Patch,
|
||||
Post,
|
||||
} from '@nestjs/common';
|
||||
|
||||
@Controller('admin/tests')
|
||||
@Roles(Role.SUPERUSER, Role.ADMIN)
|
||||
export class AdminTestsController {
|
||||
constructor(
|
||||
/**
|
||||
@@ -14,8 +24,25 @@ export class AdminTestsController {
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
@Roles(Role.SUPERUSER, Role.ADMIN)
|
||||
public async createTest(@Body() createTestDto: CreateTestDTO) {
|
||||
return await this.testsService.createOne(createTestDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
public async getAllTests() {
|
||||
return await this.testsService.adminGetAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
public async getTestById(@Param('id', ParseIntPipe) id: number) {
|
||||
return await this.testsService.adminGetOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
public async updateTestById(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Body() updateTestDto: UpdateTestDTO,
|
||||
) {
|
||||
return await this.testsService.updateOne(id, updateTestDto);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user