62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
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 { FindTestsDTO } from '@/modules/tests/dtos/find-tests.dto';
|
|
import { UpdateTestDTO } from '@/modules/tests/dtos/update-test.dto';
|
|
import { TestsService } from '@/modules/tests/providers/tests.service';
|
|
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
HttpCode,
|
|
HttpStatus,
|
|
Param,
|
|
ParseIntPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { Throttle } from '@nestjs/throttler';
|
|
|
|
@Controller('admin/tests')
|
|
@Roles(Role.SUPERUSER, Role.ADMIN)
|
|
@Throttle({ default: { limit: 120, ttl: 60_000 } })
|
|
export class AdminTestsController {
|
|
constructor(
|
|
/**
|
|
* Inject Tests Service
|
|
*/
|
|
private readonly testsService: TestsService,
|
|
) {}
|
|
|
|
@Post()
|
|
public async createTest(@Body() createTestDto: CreateTestDTO) {
|
|
return await this.testsService.createOne(createTestDto);
|
|
}
|
|
|
|
@Get()
|
|
public async getAllTests(@Query() query: FindTestsDTO) {
|
|
return await this.testsService.adminGetAll(query);
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
public async deleteTestById(@Param('id', ParseIntPipe) id: number) {
|
|
return await this.testsService.deleteOne(id);
|
|
}
|
|
}
|