feat(employees): added funcion to get employee by email
This commit is contained in:
parent
5b1746da9d
commit
183a54a89a
|
|
@ -384,6 +384,45 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/employees/profile": {
|
||||||
|
"get": {
|
||||||
|
"operationId": "EmployeesController_findOneProfile",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "email",
|
||||||
|
"required": true,
|
||||||
|
"in": "path",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Employee profile found",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/EmployeeProfileItemDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Employee profile not found"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"summary": "Find employee profile",
|
||||||
|
"tags": [
|
||||||
|
"Employees"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/timesheets": {
|
"/timesheets": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "TimesheetsController_create",
|
"operationId": "TimesheetsController_create",
|
||||||
|
|
@ -2307,6 +2346,10 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {}
|
"properties": {}
|
||||||
},
|
},
|
||||||
|
"EmployeeProfileItemDto": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {}
|
||||||
|
},
|
||||||
"UpdateEmployeeDto": {
|
"UpdateEmployeeDto": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { UpdateEmployeeDto } from '../dtos/update-employee.dto';
|
||||||
import { RolesAllowed } from '../../../common/decorators/roles.decorators';
|
import { RolesAllowed } from '../../../common/decorators/roles.decorators';
|
||||||
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { EmployeeListItemDto } from '../dtos/list-employee.dto';
|
import { EmployeeListItemDto } from '../dtos/list-employee.dto';
|
||||||
|
import { EmployeeProfileItemDto } from '../dtos/profil-employee.dto';
|
||||||
|
|
||||||
@ApiTags('Employees')
|
@ApiTags('Employees')
|
||||||
@ApiBearerAuth('access-token')
|
@ApiBearerAuth('access-token')
|
||||||
|
|
@ -50,6 +51,14 @@ export class EmployeesController {
|
||||||
return this.employeesService.findOne(id);
|
return this.employeesService.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('profile')
|
||||||
|
@ApiOperation({summary: 'Find employee profile' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Employee profile found', type: EmployeeProfileItemDto })
|
||||||
|
@ApiResponse({ status: 400, description: 'Employee profile not found' })
|
||||||
|
findOneProfile(@Param('email', ParseIntPipe)email: string): Promise<EmployeeProfileItemDto> {
|
||||||
|
return this.employeesService.findOneProfile(email);
|
||||||
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR )
|
@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR )
|
||||||
@ApiOperation({summary: 'Delete employee' })
|
@ApiOperation({summary: 'Delete employee' })
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
export class EmployeeListItemDto {
|
export class EmployeeListItemDto {
|
||||||
first_name: string;
|
first_name: string;
|
||||||
last_name: string;
|
last_name: string;
|
||||||
|
email: string;
|
||||||
supervisor_full_name: string | null;
|
supervisor_full_name: string | null;
|
||||||
company_name: number | null;
|
company_name: number | null;
|
||||||
job_title: string | null;
|
job_title: string | null;
|
||||||
|
|
|
||||||
12
src/modules/employees/dtos/profil-employee.dto.ts
Normal file
12
src/modules/employees/dtos/profil-employee.dto.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
export class EmployeeProfileItemDto {
|
||||||
|
first_name: string;
|
||||||
|
last_name: string;
|
||||||
|
supervisor_full_name: string | null;
|
||||||
|
company_name: number | null;
|
||||||
|
job_title: string | null;
|
||||||
|
email: string | null;
|
||||||
|
phone_number: number;
|
||||||
|
first_work_day: string;
|
||||||
|
last_work_day?: string | null;
|
||||||
|
residence: string | null;
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ import { UpdateEmployeeDto } from '../dtos/update-employee.dto';
|
||||||
import { Employees, EmployeesArchive, Users } from '@prisma/client';
|
import { Employees, EmployeesArchive, Users } from '@prisma/client';
|
||||||
import { EmployeeListItemDto } from '../dtos/list-employee.dto';
|
import { EmployeeListItemDto } from '../dtos/list-employee.dto';
|
||||||
import { Roles as RoleEnum } from '@prisma/client';
|
import { Roles as RoleEnum } from '@prisma/client';
|
||||||
|
import { EmployeeProfileItemDto } from '../dtos/profil-employee.dto';
|
||||||
|
|
||||||
function toDateOrNull(v?: string | null): Date | null {
|
function toDateOrNull(v?: string | null): Date | null {
|
||||||
if (!v) return null;
|
if (!v) return null;
|
||||||
|
|
@ -70,6 +71,7 @@ export class EmployeesService {
|
||||||
select: {
|
select: {
|
||||||
first_name: true,
|
first_name: true,
|
||||||
last_name: true,
|
last_name: true,
|
||||||
|
email: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
supervisor: {
|
supervisor: {
|
||||||
|
|
@ -88,6 +90,7 @@ export class EmployeesService {
|
||||||
}).then(rows => rows.map(r => ({
|
}).then(rows => rows.map(r => ({
|
||||||
first_name: r.user.first_name,
|
first_name: r.user.first_name,
|
||||||
last_name: r.user.last_name,
|
last_name: r.user.last_name,
|
||||||
|
email: r.user.email,
|
||||||
supervisor_full_name: r.supervisor ? `${r.supervisor.user.first_name} ${r.supervisor.user.last_name}` : null,
|
supervisor_full_name: r.supervisor ? `${r.supervisor.user.first_name} ${r.supervisor.user.last_name}` : null,
|
||||||
company_name: r.company_code,
|
company_name: r.company_code,
|
||||||
job_title: r.job_title,
|
job_title: r.job_title,
|
||||||
|
|
@ -106,6 +109,51 @@ export class EmployeesService {
|
||||||
return emp;
|
return emp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findOneProfile(email:string): Promise<EmployeeProfileItemDto> {
|
||||||
|
const emp = await this.prisma.employees.findFirst({
|
||||||
|
where: { user: { email } },
|
||||||
|
select: {
|
||||||
|
user: {
|
||||||
|
select: {
|
||||||
|
first_name: true,
|
||||||
|
last_name: true,
|
||||||
|
email: true,
|
||||||
|
phone_number: true,
|
||||||
|
residence: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
supervisor: {
|
||||||
|
select: {
|
||||||
|
user: {
|
||||||
|
select: {
|
||||||
|
first_name: true,
|
||||||
|
last_name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
job_title: true,
|
||||||
|
company_code: true,
|
||||||
|
first_work_day: true,
|
||||||
|
last_work_day: true,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!emp) throw new NotFoundException(`Employee with email ${email} not found`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
first_name: emp.user.first_name,
|
||||||
|
last_name: emp.user.last_name,
|
||||||
|
email: emp.user.email,
|
||||||
|
residence: emp.user.residence,
|
||||||
|
phone_number: emp.user.phone_number,
|
||||||
|
supervisor_full_name: emp.supervisor ? `${emp.supervisor.user.first_name}, ${emp.supervisor.user.last_name}` : null,
|
||||||
|
company_name: emp.company_code,
|
||||||
|
job_title: emp.job_title,
|
||||||
|
first_work_day: emp.first_work_day.toISOString().slice(0,10),
|
||||||
|
last_work_day: emp.last_work_day ? emp.last_work_day.toISOString().slice(0,10) : null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async update(
|
async update(
|
||||||
id: number,
|
id: number,
|
||||||
dto: UpdateEmployeeDto,
|
dto: UpdateEmployeeDto,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user