65 lines
3.1 KiB
TypeScript
65 lines
3.1 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post, UseGuards } from "@nestjs/common";
|
|
import { ShiftCodesService } from "../services/shift-codes.service";
|
|
import { CreateShiftCodeDto } from "../dtos/create-shift-codes.dto";
|
|
import { ShiftCodes } from "@prisma/client";
|
|
import { UpdateShiftCodeDto } from "../dtos/update-shift-codes.dto";
|
|
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
|
import { Roles as RoleEnum } from '.prisma/client';
|
|
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
|
import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard";
|
|
import { ShiftCodesEntity } from "../dtos/swagger-entities/shift-codes.entity";
|
|
|
|
@ApiTags('Shift Codes')
|
|
@ApiBearerAuth('access-token')
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('shift-codes')
|
|
export class ShiftCodesController {
|
|
constructor(private readonly shiftCodesService: ShiftCodesService) {}
|
|
|
|
@Post()
|
|
@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR)
|
|
@ApiOperation({ summary: 'Create shift code' })
|
|
@ApiResponse({ status: 201, description: 'Shift code created',type: ShiftCodesEntity })
|
|
@ApiResponse({ status: 400, description: 'Incomplete task or invalid data' })
|
|
create(@Body()dto: CreateShiftCodeDto): Promise<ShiftCodes> {
|
|
return this.shiftCodesService.create(dto);
|
|
}
|
|
|
|
@Get()
|
|
@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR)
|
|
@ApiOperation({ summary: 'Find all shift codes' })
|
|
@ApiResponse({ status: 201, description: 'List of shift codes found',type: ShiftCodesEntity, isArray: true })
|
|
@ApiResponse({ status: 400, description: 'List of shift codes not found' })
|
|
findAll(): Promise<ShiftCodes[]> {
|
|
return this.shiftCodesService.findAll();
|
|
}
|
|
|
|
@Get(':id')
|
|
@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR)
|
|
@ApiOperation({ summary: 'Find shift code' })
|
|
@ApiResponse({ status: 201, description: 'Shift code found',type: ShiftCodesEntity })
|
|
@ApiResponse({ status: 400, description: 'Shift code not found' })
|
|
findOne(@Param('id', ParseIntPipe) id: number): Promise<ShiftCodes> {
|
|
return this.shiftCodesService.findOne(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR)
|
|
@ApiOperation({ summary: 'Update shift code' })
|
|
@ApiResponse({ status: 201, description: 'Shift code updated',type: ShiftCodesEntity })
|
|
@ApiResponse({ status: 400, description: 'Shift code not found' })
|
|
update(@Param('id', ParseIntPipe) id: number,
|
|
@Body() dto: UpdateShiftCodeDto): Promise<ShiftCodes> {
|
|
return this.shiftCodesService.update(id,dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR)
|
|
@ApiOperation({ summary: 'Delete shift code' })
|
|
@ApiResponse({ status: 201, description: 'Shift code deleted',type: ShiftCodesEntity })
|
|
@ApiResponse({ status: 400, description: 'Shift code not found' })
|
|
remove(@Param('id', ParseIntPipe)id: number): Promise<ShiftCodes> {
|
|
return this.shiftCodesService.remove(id);
|
|
}
|
|
}
|