fix(employees): fix create employees

This commit is contained in:
Matthieu Haineault 2025-12-03 15:57:30 -05:00
parent f8a70deed2
commit b44577c595
3 changed files with 4 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import { Type } from 'class-transformer';
export class EmployeeDetailedDto {
@IsString() @IsNotEmpty() first_name: string;
@IsString() @IsNotEmpty() last_name: string;
@IsString() employee_full_name: string;
@IsString() @IsOptional() employee_full_name: string;
@IsString() @IsOptional() supervisor_full_name: string;
@IsOptional() @IsBoolean() is_supervisor: boolean;
@IsString() company_name: string;

View File

@ -14,6 +14,7 @@ export class EmployeesCreateService {
const normalized_access = toBooleanFromString(dto.user_module_access);
const supervisor_id = await this.toIdFromFullName(dto.supervisor_full_name);
const company_code = toCompanyCodeFromString(dto.company_name)
await this.prisma.$transaction(async (tx) => {
const user: Users = await tx.users.create({
data: {
@ -40,7 +41,6 @@ export class EmployeesCreateService {
company_code: company_code,
job_title: dto.job_title,
first_work_day: dto.first_work_day,
last_work_day: dto.last_work_day,
is_supervisor: dto.is_supervisor,
supervisor_id: supervisor_id,
},

View File

@ -2,6 +2,7 @@ import { Injectable } from "@nestjs/common";
import { Result } from "src/common/errors/result-error.factory";
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
import { toBooleanFromString } from "src/common/mappers/module-access.mapper";
import { toDateFromString } from "src/common/utils/date-utils";
import { EmployeeDetailedDto } from "src/identity-and-account/employees/dtos/employee-detailed.dto";
import { toCompanyCodeFromString } from "src/identity-and-account/employees/utils/employee.utils";
import { PrismaService } from "src/prisma/prisma.service";
@ -58,7 +59,7 @@ export class EmployeesUpdateService {
data: {
company_code: company_code,
job_title: dto.job_title,
first_work_day: dto.first_work_day,
first_work_day: toDateFromString(dto.first_work_day),
last_work_day: dto.last_work_day,
is_supervisor: dto.is_supervisor,
supervisor_id: supervisor_id,