32 lines
1.4 KiB
TypeScript
32 lines
1.4 KiB
TypeScript
import { Get, Param, ParseIntPipe, NotFoundException, Controller, UseGuards } from "@nestjs/common";
|
|
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
|
import { ShiftsArchive, Roles as RoleEnum } from "@prisma/client";
|
|
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
|
import { ShiftsQueryService } from "src/modules/shifts/services/shifts-query.service";
|
|
|
|
@ApiTags('Shift Archives')
|
|
// @UseGuards()
|
|
@Controller('archives/shifts')
|
|
export class ShiftsArchiveController {
|
|
constructor(private readonly shiftsService:ShiftsQueryService) {}
|
|
|
|
@Get()
|
|
@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
|
@ApiOperation({ summary: 'List of archived shifts'})
|
|
@ApiResponse({ status: 200, description: 'List of archived shifts', isArray: true })
|
|
async findAllArchived(): Promise<ShiftsArchive[]> {
|
|
return this.shiftsService.findAllArchived();
|
|
}
|
|
|
|
@Get()
|
|
@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR,RoleEnum.SUPERVISOR)
|
|
@ApiOperation({ summary: 'Fetch shift in archives with its Id'})
|
|
@ApiResponse({ status: 200, description: 'Archived shift found'})
|
|
async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<ShiftsArchive> {
|
|
try{
|
|
return await this.shiftsService.findOneArchived(id);
|
|
}catch {
|
|
throw new NotFoundException(`Archived shift #${id} not found`);
|
|
}
|
|
}
|
|
} |