100 lines
5.0 KiB
TypeScript
100 lines
5.0 KiB
TypeScript
import { Body,Controller,Get,NotFoundException,Param,Patch } from '@nestjs/common';
|
|
import { EmployeesService } from '../services/employees.service';
|
|
import { CreateEmployeeDto } from '../dtos/create-employee.dto';
|
|
import { UpdateEmployeeDto } from '../dtos/update-employee.dto';
|
|
import { RolesAllowed } from '../../../common/decorators/roles.decorators';
|
|
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
import { EmployeeListItemDto } from '../dtos/list-employee.dto';
|
|
import { EmployeesArchivalService } from '../services/employees-archival.service';
|
|
import { EmployeeProfileItemDto } from 'src/modules/employees/dtos/profil-employee.dto';
|
|
|
|
@ApiTags('Employees')
|
|
@ApiBearerAuth('access-token')
|
|
// @UseGuards()
|
|
@Controller('employees')
|
|
export class EmployeesController {
|
|
constructor(
|
|
private readonly employeesService: EmployeesService,
|
|
private readonly archiveService: EmployeesArchivalService,
|
|
) {}
|
|
|
|
@Get('employee-list')
|
|
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR, RoleEnum.ACCOUNTING)
|
|
@ApiOperation({summary: 'Find all employees with scoped info' })
|
|
@ApiResponse({ status: 200, description: 'List of employees with scoped info found', type: EmployeeListItemDto, isArray: true })
|
|
@ApiResponse({ status: 400, description: 'List of employees with scoped info not found' })
|
|
findListEmployees(): Promise<EmployeeListItemDto[]> {
|
|
return this.employeesService.findListEmployees();
|
|
}
|
|
|
|
@Patch(':email')
|
|
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
|
@ApiBearerAuth('access-token')
|
|
@ApiOperation({ summary: 'Update, archive or restore an employee' })
|
|
@ApiParam({ name: 'email', type: Number, description: 'Email of the employee' })
|
|
@ApiResponse({ status: 200, description: 'Employee updated or restored', type: CreateEmployeeDto })
|
|
@ApiResponse({ status: 202, description: 'Employee archived successfully', type: CreateEmployeeDto })
|
|
@ApiResponse({ status: 404, description: 'Employee not found in active or archive' })
|
|
async updateOrArchiveOrRestore(@Param('email') email: string, @Body() dto: UpdateEmployeeDto,) {
|
|
// if last_work_day is set => archive the employee
|
|
// else if employee is archived and first_work_day or last_work_day = null => restore
|
|
//otherwise => standard update
|
|
const result = await this.archiveService.patchEmployee(email, dto);
|
|
if(!result) {
|
|
throw new NotFoundException(`Employee with email: ${ email } is not found in active or archive.`)
|
|
}
|
|
return result;
|
|
}
|
|
|
|
//_____________________________________________________________________________________________
|
|
// Deprecated or unused methods
|
|
//_____________________________________________________________________________________________
|
|
|
|
// @Post()
|
|
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
|
// @ApiOperation({summary: 'Create employee' })
|
|
// @ApiResponse({ status: 201, description: 'Employee created', type: CreateEmployeeDto })
|
|
// @ApiResponse({ status: 400, description: 'Incomplete task or invalid data' })
|
|
// create(@Body() dto: CreateEmployeeDto): Promise<Employees> {
|
|
// return this.employeesService.create(dto);
|
|
// }
|
|
// @Get()
|
|
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR, RoleEnum.ACCOUNTING)
|
|
// @ApiOperation({summary: 'Find all employees' })
|
|
// @ApiResponse({ status: 200, description: 'List of employees found', type: CreateEmployeeDto, isArray: true })
|
|
// @ApiResponse({ status: 400, description: 'List of employees not found' })
|
|
// findAll(): Promise<Employees[]> {
|
|
// return this.employeesService.findAll();
|
|
// }
|
|
|
|
|
|
// @Get(':email')
|
|
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR,RoleEnum.ACCOUNTING )
|
|
// @ApiOperation({summary: 'Find employee' })
|
|
// @ApiResponse({ status: 200, description: 'Employee found', type: CreateEmployeeDto })
|
|
// @ApiResponse({ status: 400, description: 'Employee not found' })
|
|
// findOne(@Param('email', ParseIntPipe) email: string): Promise<Employees> {
|
|
// return this.employeesService.findOne(email);
|
|
// }
|
|
|
|
@Get('profile/:email')
|
|
@ApiOperation({summary: 'Find employee profile' })
|
|
@ApiParam({ name: 'email', type: String, description: 'Identifier of the employee' })
|
|
@ApiResponse({ status: 200, description: 'Employee profile found', type: EmployeeProfileItemDto })
|
|
@ApiResponse({ status: 400, description: 'Employee profile not found' })
|
|
findOneProfile(@Param('email') email: string): Promise<EmployeeProfileItemDto> {
|
|
return this.employeesService.findOneProfile(email);
|
|
}
|
|
|
|
// @Delete(':email')
|
|
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR )
|
|
// @ApiOperation({summary: 'Delete employee' })
|
|
// @ApiParam({ name: 'email', type: Number, description: 'Email of the employee to delete' })
|
|
// @ApiResponse({ status: 204, description: 'Employee deleted' })
|
|
// @ApiResponse({ status: 404, description: 'Employee not found' })
|
|
// remove(@Param('email', ParseIntPipe) email: string): Promise<Employees> {
|
|
// return this.employeesService.remove(email);
|
|
// }
|
|
|
|
}
|