fix(employee): setting up the profil section
This commit is contained in:
parent
e34658fc41
commit
809209533a
|
|
@ -1,6 +1,8 @@
|
||||||
import { Controller, Get, Patch, Param, Body, NotFoundException } from "@nestjs/common";
|
import { Controller, Get, Patch, Param, Body, NotFoundException, Req, Post } from "@nestjs/common";
|
||||||
|
import { Employees } from "@prisma/client";
|
||||||
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
||||||
import { GLOBAL_CONTROLLER_ROLES, MANAGER_ROLES } from "src/common/shared/role-groupes";
|
import { GLOBAL_CONTROLLER_ROLES, MANAGER_ROLES } from "src/common/shared/role-groupes";
|
||||||
|
import { CreateEmployeeDto } from "src/identity-and-account/employees/dtos/create-employee.dto";
|
||||||
import { EmployeeListItemDto } from "src/identity-and-account/employees/dtos/list-employee.dto";
|
import { EmployeeListItemDto } from "src/identity-and-account/employees/dtos/list-employee.dto";
|
||||||
import { EmployeeProfileItemDto } from "src/identity-and-account/employees/dtos/profil-employee.dto";
|
import { EmployeeProfileItemDto } from "src/identity-and-account/employees/dtos/profil-employee.dto";
|
||||||
import { UpdateEmployeeDto } from "src/identity-and-account/employees/dtos/update-employee.dto";
|
import { UpdateEmployeeDto } from "src/identity-and-account/employees/dtos/update-employee.dto";
|
||||||
|
|
@ -15,8 +17,9 @@ export class EmployeesController {
|
||||||
private readonly archiveService: EmployeesArchivalService,
|
private readonly archiveService: EmployeesArchivalService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
@Get('profile/:email')
|
@Get('profile')
|
||||||
findOneProfile(@Param('email') email: string): Promise<EmployeeProfileItemDto> {
|
findOneProfile(@Req() req): Promise<EmployeeProfileItemDto> {
|
||||||
|
const email = req.user?.email;
|
||||||
return this.employeesService.findOneProfile(email);
|
return this.employeesService.findOneProfile(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,12 +29,13 @@ export class EmployeesController {
|
||||||
return this.employeesService.findListEmployees();
|
return this.employeesService.findListEmployees();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':email')
|
@Patch()
|
||||||
@RolesAllowed(...MANAGER_ROLES)
|
@RolesAllowed(...MANAGER_ROLES)
|
||||||
async updateOrArchiveOrRestore(@Param('email') email: string, @Body() dto: UpdateEmployeeDto,) {
|
async updateOrArchiveOrRestore(@Req() req, @Body() dto: UpdateEmployeeDto,) {
|
||||||
// if last_work_day is set => archive the employee
|
// if last_work_day is set => archive the employee
|
||||||
// else if employee is archived and first_work_day or last_work_day = null => restore
|
// else if employee is archived and first_work_day or last_work_day = null => restore
|
||||||
//otherwise => standard update
|
//otherwise => standard update
|
||||||
|
const email = req.user?.email;
|
||||||
const result = await this.archiveService.patchEmployee(email, dto);
|
const result = await this.archiveService.patchEmployee(email, dto);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new NotFoundException(`Employee with email: ${email} is not found in active or archive.`)
|
throw new NotFoundException(`Employee with email: ${email} is not found in active or archive.`)
|
||||||
|
|
@ -39,29 +43,10 @@ export class EmployeesController {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
@RolesAllowed(...MANAGER_ROLES)
|
||||||
//_____________________________________________________________________________________________
|
create(@Body() dto: CreateEmployeeDto): Promise<Employees> {
|
||||||
// Deprecated or unused methods
|
return this.employeesService.create(dto);
|
||||||
//_____________________________________________________________________________________________
|
}
|
||||||
|
|
||||||
// @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);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @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);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||||
|
import { Employees, Users } from "@prisma/client";
|
||||||
|
import { CreateEmployeeDto } from "src/identity-and-account/employees/dtos/create-employee.dto";
|
||||||
import { EmployeeListItemDto } from "src/identity-and-account/employees/dtos/list-employee.dto";
|
import { EmployeeListItemDto } from "src/identity-and-account/employees/dtos/list-employee.dto";
|
||||||
import { EmployeeProfileItemDto } from "src/identity-and-account/employees/dtos/profil-employee.dto";
|
import { EmployeeProfileItemDto } from "src/identity-and-account/employees/dtos/profil-employee.dto";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
|
|
@ -88,48 +90,50 @@ export class EmployeesService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async create(dto: CreateEmployeeDto): Promise<Employees> {
|
||||||
|
const {
|
||||||
|
first_name,
|
||||||
|
last_name,
|
||||||
|
email,
|
||||||
|
phone_number,
|
||||||
|
residence,
|
||||||
|
external_payroll_id,
|
||||||
|
company_code,
|
||||||
|
job_title,
|
||||||
|
first_work_day,
|
||||||
|
last_work_day,
|
||||||
|
is_supervisor,
|
||||||
|
} = dto;
|
||||||
|
|
||||||
|
return this.prisma.$transaction(async (transaction) => {
|
||||||
|
const user: Users = await transaction.users.create({
|
||||||
|
data: {
|
||||||
|
first_name,
|
||||||
|
last_name,
|
||||||
|
email,
|
||||||
|
phone_number,
|
||||||
|
residence,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return transaction.employees.create({
|
||||||
|
data: {
|
||||||
|
user_id: user.id,
|
||||||
|
external_payroll_id,
|
||||||
|
company_code,
|
||||||
|
job_title,
|
||||||
|
first_work_day,
|
||||||
|
last_work_day,
|
||||||
|
is_supervisor,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//_____________________________________________________________________________________________
|
//_____________________________________________________________________________________________
|
||||||
// Deprecated or unused methods
|
// Deprecated or unused methods
|
||||||
//_____________________________________________________________________________________________
|
//_____________________________________________________________________________________________
|
||||||
|
|
||||||
// async create(dto: CreateEmployeeDto): Promise<Employees> {
|
|
||||||
// const {
|
|
||||||
// first_name,
|
|
||||||
// last_name,
|
|
||||||
// email,
|
|
||||||
// phone_number,
|
|
||||||
// residence,
|
|
||||||
// external_payroll_id,
|
|
||||||
// company_code,
|
|
||||||
// job_title,
|
|
||||||
// first_work_day,
|
|
||||||
// last_work_day,
|
|
||||||
// is_supervisor,
|
|
||||||
// } = dto;
|
|
||||||
|
|
||||||
// return this.prisma.$transaction(async (transaction) => {
|
|
||||||
// const user: Users = await transaction.users.create({
|
|
||||||
// data: {
|
|
||||||
// first_name,
|
|
||||||
// last_name,
|
|
||||||
// email,
|
|
||||||
// phone_number,
|
|
||||||
// residence,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// return transaction.employees.create({
|
|
||||||
// data: {
|
|
||||||
// user_id: user.id,
|
|
||||||
// external_payroll_id,
|
|
||||||
// company_code,
|
|
||||||
// job_title,
|
|
||||||
// first_work_day,
|
|
||||||
// last_work_day,
|
|
||||||
// is_supervisor,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// findAll(): Promise<Employees[]> {
|
// findAll(): Promise<Employees[]> {
|
||||||
// return this.prisma.employees.findMany({
|
// return this.prisma.employees.findMany({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user