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