refactor(cleaning): preparing other modules for refactoring

This commit is contained in:
Matthieu Haineault 2025-10-24 16:47:30 -04:00
parent 1289aed720
commit 2712033451
22 changed files with 819 additions and 821 deletions

View File

@ -14,48 +14,48 @@ datasource db {
url = env("DATABASE_URL_DEV") url = env("DATABASE_URL_DEV")
} }
model Users { // model Users {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid // id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
first_name String // first_name String
last_name String // last_name String
email String @unique // email String @unique
phone_number String @unique // phone_number String @unique
residence String? // residence String?
role Roles @default(GUEST) // role Roles @default(GUEST)
employee Employees? @relation("UserEmployee") // employee Employees? @relation("UserEmployee")
oauth_sessions OAuthSessions[] @relation("UserOAuthSessions") // oauth_sessions OAuthSessions[] @relation("UserOAuthSessions")
preferences Preferences? @relation("UserPreferences") // preferences Preferences? @relation("UserPreferences")
@@map("users") // @@map("users")
} // }
model Employees { // model Employees {
id Int @id @default(autoincrement()) // id Int @id @default(autoincrement())
user Users @relation("UserEmployee", fields: [user_id], references: [id]) // user Users @relation("UserEmployee", fields: [user_id], references: [id])
user_id String @unique @db.Uuid // user_id String @unique @db.Uuid
supervisor Employees? @relation("EmployeeSupervisor", fields: [supervisor_id], references: [id]) // supervisor Employees? @relation("EmployeeSupervisor", fields: [supervisor_id], references: [id])
supervisor_id Int? // supervisor_id Int?
external_payroll_id Int // external_payroll_id Int
company_code Int // company_code Int
first_work_day DateTime @db.Date // first_work_day DateTime @db.Date
last_work_day DateTime? @db.Date // last_work_day DateTime? @db.Date
job_title String? // job_title String?
is_supervisor Boolean @default(false) // is_supervisor Boolean @default(false)
crew Employees[] @relation("EmployeeSupervisor") // crew Employees[] @relation("EmployeeSupervisor")
timesheet Timesheets[] @relation("TimesheetEmployee") // timesheet Timesheets[] @relation("TimesheetEmployee")
leave_request LeaveRequests[] @relation("LeaveRequestEmployee") // leave_request LeaveRequests[] @relation("LeaveRequestEmployee")
schedule_presets SchedulePresets[] @relation("SchedulePreset") // schedule_presets SchedulePresets[] @relation("SchedulePreset")
@@map("employees") // @@map("employees")
} // }
model LeaveRequests { model LeaveRequests {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
employee Employees @relation("LeaveRequestEmployee", fields: [employee_id], references: [id]) // employee Employees @relation("LeaveRequestEmployee", fields: [employee_id], references: [id])
employee_id Int employee_id Int
bank_code BankCodes @relation("LeaveRequestBankCodes", fields: [bank_code_id], references: [id]) bank_code BankCodes @relation("LeaveRequestBankCodes", fields: [bank_code_id], references: [id])
bank_code_id Int bank_code_id Int
@ -107,7 +107,7 @@ view PayPeriods {
model Timesheets { model Timesheets {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
employee Employees @relation("TimesheetEmployee", fields: [employee_id], references: [id]) // employee Employees @relation("TimesheetEmployee", fields: [employee_id], references: [id])
employee_id Int employee_id Int
start_date DateTime @db.Date start_date DateTime @db.Date
@ -135,7 +135,7 @@ model TimesheetsArchive {
model SchedulePresets { model SchedulePresets {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
employee Employees @relation("SchedulePreset", fields: [employee_id], references: [id]) // employee Employees @relation("SchedulePreset", fields: [employee_id], references: [id])
employee_id Int employee_id Int
name String name String
@ -258,7 +258,7 @@ model ExpensesArchive {
model OAuthSessions { model OAuthSessions {
id String @id @default(cuid()) id String @id @default(cuid())
user Users @relation("UserOAuthSessions", fields: [user_id], references: [id]) // user Users @relation("UserOAuthSessions", fields: [user_id], references: [id])
user_id String @db.Uuid user_id String @db.Uuid
application String application String
access_token String @unique access_token String @unique
@ -327,7 +327,7 @@ model AttachmentVariants {
model Preferences { model Preferences {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
user Users @relation("UserPreferences", fields: [user_id], references: [id]) // user Users @relation("UserPreferences", fields: [user_id], references: [id])
user_id String @unique @db.Uuid user_id String @unique @db.Uuid
notifications Int @default(0) notifications Int @default(0)

View File

@ -3,7 +3,7 @@ import { AppController } from './app.controller';
import { AppService } from './app.service'; import { AppService } from './app.service';
// import { ArchivalModule } from './modules/archival/archival.module'; // import { ArchivalModule } from './modules/archival/archival.module';
import { AuthenticationModule } from './modules/authentication/auth.module'; import { AuthenticationModule } from './modules/authentication/auth.module';
import { BankCodesModule } from './modules/bank-codes/bank-codes.module'; // import { BankCodesModule } from './modules/bank-codes/bank-codes.module';
// import { CsvExportModule } from './modules/exports/csv-exports.module'; // import { CsvExportModule } from './modules/exports/csv-exports.module';
import { HealthModule } from './health/health.module'; import { HealthModule } from './health/health.module';
import { HealthController } from './health/health.controller'; import { HealthController } from './health/health.controller';
@ -23,7 +23,7 @@ import { TimeAndAttendanceModule } from 'src/time-and-attendance/time-and-attend
@Module({ @Module({
imports: [ imports: [
AuthenticationModule, AuthenticationModule,
BankCodesModule, // BankCodesModule,
ConfigModule.forRoot({isGlobal: true}), ConfigModule.forRoot({isGlobal: true}),
// CsvExportModule, // CsvExportModule,
// CustomersModule, // CustomersModule,

View File

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

View File

@ -1,7 +1,7 @@
import { Controller } from '@nestjs/common'; // import { Controller } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger'; // import { ApiTags } from '@nestjs/swagger';
@ApiTags('LeaveRequests Archives') // @ApiTags('LeaveRequests Archives')
// @UseGuards() // // @UseGuards()
@Controller('archives/leaveRequests') // @Controller('archives/leaveRequests')
export class LeaveRequestsArchiveController {} // export class LeaveRequestsArchiveController {}

View File

@ -1,32 +1,32 @@
import { Get, Param, ParseIntPipe, NotFoundException, Controller, UseGuards } from "@nestjs/common"; // import { Get, Param, ParseIntPipe, NotFoundException, Controller, UseGuards } from "@nestjs/common";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; // import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import { ShiftsArchive, Roles as RoleEnum } from "@prisma/client"; // import { ShiftsArchive, Roles as RoleEnum } from "@prisma/client";
import { RolesAllowed } from "src/common/decorators/roles.decorators"; // import { RolesAllowed } from "src/common/decorators/roles.decorators";
import { ShiftsArchivalService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-archival.service"; // import { ShiftsArchivalService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-archival.service";
@ApiTags('Shift Archives') // @ApiTags('Shift Archives')
// @UseGuards() // // @UseGuards()
@Controller('archives/shifts') // @Controller('archives/shifts')
export class ShiftsArchiveController { // export class ShiftsArchiveController {
constructor(private readonly shiftsService: ShiftsArchivalService) {} // constructor(private readonly shiftsService: ShiftsArchivalService) {}
@Get() // @Get()
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) // //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
@ApiOperation({ summary: 'List of archived shifts'}) // @ApiOperation({ summary: 'List of archived shifts'})
@ApiResponse({ status: 200, description: 'List of archived shifts', isArray: true }) // @ApiResponse({ status: 200, description: 'List of archived shifts', isArray: true })
async findAllArchived(): Promise<ShiftsArchive[]> { // async findAllArchived(): Promise<ShiftsArchive[]> {
return this.shiftsService.findAllArchived(); // return this.shiftsService.findAllArchived();
} // }
@Get() // @Get()
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR,RoleEnum.SUPERVISOR) // //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR,RoleEnum.SUPERVISOR)
@ApiOperation({ summary: 'Fetch shift in archives with its Id'}) // @ApiOperation({ summary: 'Fetch shift in archives with its Id'})
@ApiResponse({ status: 200, description: 'Archived shift found'}) // @ApiResponse({ status: 200, description: 'Archived shift found'})
async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<ShiftsArchive> { // async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<ShiftsArchive> {
try{ // try{
return await this.shiftsService.findOneArchived(id); // return await this.shiftsService.findOneArchived(id);
}catch { // }catch {
throw new NotFoundException(`Archived shift #${id} not found`); // throw new NotFoundException(`Archived shift #${id} not found`);
} // }
} // }
} // }

View File

@ -1,33 +1,33 @@
import { Controller, Get, NotFoundException, Param, ParseIntPipe, UseGuards } from "@nestjs/common"; // import { Controller, Get, NotFoundException, Param, ParseIntPipe, UseGuards } from "@nestjs/common";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; // import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import { RolesAllowed } from "src/common/decorators/roles.decorators"; // import { RolesAllowed } from "src/common/decorators/roles.decorators";
import { TimesheetsArchive, Roles as RoleEnum } from '@prisma/client'; // import { TimesheetsArchive, Roles as RoleEnum } from '@prisma/client';
import { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service"; // import { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service";
@ApiTags('Timesheet Archives') // @ApiTags('Timesheet Archives')
// @UseGuards() // // @UseGuards()
@Controller('archives/timesheets') // @Controller('archives/timesheets')
export class TimesheetsArchiveController { // export class TimesheetsArchiveController {
constructor(private readonly timesheetsService: TimesheetArchiveService) {} // constructor(private readonly timesheetsService: TimesheetArchiveService) {}
@Get() // @Get()
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) // //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
@ApiOperation({ summary: 'List of archived timesheets'}) // @ApiOperation({ summary: 'List of archived timesheets'})
@ApiResponse({ status: 200, description: 'List of archived timesheets', isArray: true }) // @ApiResponse({ status: 200, description: 'List of archived timesheets', isArray: true })
async findAllArchived(): Promise<TimesheetsArchive[]> { // async findAllArchived(): Promise<TimesheetsArchive[]> {
return this.timesheetsService.findAllArchived(); // return this.timesheetsService.findAllArchived();
} // }
@Get() // @Get()
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) // //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
@ApiOperation({ summary: 'Fetch timesheet in archives with its Id'}) // @ApiOperation({ summary: 'Fetch timesheet in archives with its Id'})
@ApiResponse({ status: 200, description: 'Archived timesheet found'}) // @ApiResponse({ status: 200, description: 'Archived timesheet found'})
async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<TimesheetsArchive> { // async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<TimesheetsArchive> {
try{ // try{
return await this.timesheetsService.findOneArchived(id); // return await this.timesheetsService.findOneArchived(id);
}catch { // }catch {
throw new NotFoundException(`Archived timesheet #${id} not found`); // throw new NotFoundException(`Archived timesheet #${id} not found`);
} // }
} // }
} // }

View File

@ -1,38 +1,38 @@
import { Injectable, Logger } from "@nestjs/common"; // import { Injectable, Logger } from "@nestjs/common";
import { Cron } from "@nestjs/schedule"; // import { Cron } from "@nestjs/schedule";
import { ExpensesArchivalService } from "src/time-and-attendance/modules/expenses/services/expenses-archival.service"; // import { ExpensesArchivalService } from "src/time-and-attendance/modules/expenses/services/expenses-archival.service";
import { ShiftsArchivalService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-archival.service"; // import { ShiftsArchivalService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-archival.service";
import { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service"; // import { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service";
@Injectable() // @Injectable()
export class ArchivalService { // export class ArchivalService {
private readonly logger = new Logger(ArchivalService.name); // private readonly logger = new Logger(ArchivalService.name);
constructor( // constructor(
private readonly timesheetsService: TimesheetArchiveService, // private readonly timesheetsService: TimesheetArchiveService,
private readonly expensesService: ExpensesArchivalService, // private readonly expensesService: ExpensesArchivalService,
private readonly shiftsService: ShiftsArchivalService, // private readonly shiftsService: ShiftsArchivalService,
) {} // ) {}
@Cron('0 0 3 * * 1', {timeZone:'America/Toronto'}) // chaque premier lundi du mois à 03h00 // @Cron('0 0 3 * * 1', {timeZone:'America/Toronto'}) // chaque premier lundi du mois à 03h00
async handleMonthlyArchival() { // async handleMonthlyArchival() {
const today = new Date(); // const today = new Date();
const dayOfMonth = today.getDate(); // const dayOfMonth = today.getDate();
if (dayOfMonth > 7) { // if (dayOfMonth > 7) {
this.logger.warn('Archive {awaiting 1st monday of the month for archivation process}') // this.logger.warn('Archive {awaiting 1st monday of the month for archivation process}')
return; // return;
} // }
this.logger.log('monthly archivation in process'); // this.logger.log('monthly archivation in process');
try { // try {
await this.timesheetsService.archiveOld(); // await this.timesheetsService.archiveOld();
await this.expensesService.archiveOld(); // await this.expensesService.archiveOld();
await this.shiftsService.archiveOld(); // await this.shiftsService.archiveOld();
// await this.leaveRequestsService.archiveExpired(); // // await this.leaveRequestsService.archiveExpired();
this.logger.log('archivation process done'); // this.logger.log('archivation process done');
} catch (err) { // } catch (err) {
this.logger.error('an error occured during archivation process ', err); // this.logger.error('an error occured during archivation process ', err);
} // }
} // }
} // }

View File

@ -4,9 +4,7 @@ import {
Controller,NotFoundException, UseInterceptors, Post, Get, Param, Res, Controller,NotFoundException, UseInterceptors, Post, Get, Param, Res,
UploadedFile, BadRequestException, UnsupportedMediaTypeException, Body, Delete, UploadedFile, BadRequestException, UnsupportedMediaTypeException, Body, Delete,
Query, Query,
DefaultValuePipe, } from "@nestjs/common";
ParseIntPipe
} from "@nestjs/common";
import { maxUploadBytes, allowedMimes } from "../config/upload.config"; import { maxUploadBytes, allowedMimes } from "../config/upload.config";
import { memoryStorage } from 'multer'; import { memoryStorage } from 'multer';
import { fileTypeFromBuffer, fileTypeFromFile } from "file-type"; import { fileTypeFromBuffer, fileTypeFromFile } from "file-type";

View File

@ -1,11 +1,11 @@
import { Module } from "@nestjs/common"; // import { Module } from "@nestjs/common";
import { PrismaService } from "src/prisma/prisma.service"; // import { PrismaService } from "src/prisma/prisma.service";
import { BankCodesControllers } from "./controllers/bank-codes.controller"; // import { BankCodesControllers } from "./controllers/bank-codes.controller";
import { BankCodesService } from "./services/bank-codes.service"; // import { BankCodesService } from "./services/bank-codes.service";
@Module({ // @Module({
controllers: [BankCodesControllers], // controllers: [BankCodesControllers],
providers: [BankCodesService, PrismaService], // providers: [BankCodesService, PrismaService],
}) // })
export class BankCodesModule {} // export class BankCodesModule {}

View File

@ -1,49 +1,49 @@
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from "@nestjs/common"; // import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from "@nestjs/common";
import { BankCodesService } from "../services/bank-codes.service"; // import { BankCodesService } from "../services/bank-codes.service";
import { CreateBankCodeDto } from "../dtos/create-bank-code.dto"; // import { CreateBankCodeDto } from "../dtos/create-bank-code.dto";
import { UpdateBankCodeDto } from "../dtos/update-bank-code.dto"; // import { UpdateBankCodeDto } from "../dtos/update-bank-code.dto";
import { ApiBadRequestResponse, ApiNotFoundResponse, ApiOperation, ApiResponse } from "@nestjs/swagger"; // import { ApiBadRequestResponse, ApiNotFoundResponse, ApiOperation, ApiResponse } from "@nestjs/swagger";
@Controller('bank-codes') // @Controller('bank-codes')
export class BankCodesControllers { // export class BankCodesControllers {
constructor(private readonly bankCodesService: BankCodesService) {} // constructor(private readonly bankCodesService: BankCodesService) {}
//_____________________________________________________________________________________________ // //_____________________________________________________________________________________________
// Deprecated or unused methods // // Deprecated or unused methods
//_____________________________________________________________________________________________ // //_____________________________________________________________________________________________
// @Post() // // @Post()
// @ApiOperation({ summary: 'Create a new bank code' }) // // @ApiOperation({ summary: 'Create a new bank code' })
// @ApiResponse({ status: 201, description: 'Bank code successfully created.' }) // // @ApiResponse({ status: 201, description: 'Bank code successfully created.' })
// @ApiBadRequestResponse({ description: 'Invalid input data.' }) // // @ApiBadRequestResponse({ description: 'Invalid input data.' })
// create(@Body() dto: CreateBankCodeDto) { // // create(@Body() dto: CreateBankCodeDto) {
// return this.bankCodesService.create(dto); // // return this.bankCodesService.create(dto);
// } // // }
// @Get() // // @Get()
// @ApiOperation({ summary: 'Retrieve all bank codes' }) // // @ApiOperation({ summary: 'Retrieve all bank codes' })
// @ApiResponse({ status: 200, description: 'List of bank codes.' }) // // @ApiResponse({ status: 200, description: 'List of bank codes.' })
// findAll() { // // findAll() {
// return this.bankCodesService.findAll(); // // return this.bankCodesService.findAll();
// } // // }
// @Get(':id') // // @Get(':id')
// @ApiOperation({ summary: 'Retrieve a bank code by its ID' }) // // @ApiOperation({ summary: 'Retrieve a bank code by its ID' })
// @ApiNotFoundResponse({ description: 'Bank code not found.' }) // // @ApiNotFoundResponse({ description: 'Bank code not found.' })
// findOne(@Param('id', ParseIntPipe) id: number){ // // findOne(@Param('id', ParseIntPipe) id: number){
// return this.bankCodesService.findOne(id); // // return this.bankCodesService.findOne(id);
// } // // }
// @Patch(':id') // // @Patch(':id')
// @ApiOperation({ summary: 'Update an existing bank code' }) // // @ApiOperation({ summary: 'Update an existing bank code' })
// @ApiNotFoundResponse({ description: 'Bank code not found.' }) // // @ApiNotFoundResponse({ description: 'Bank code not found.' })
// update(@Param('id', ParseIntPipe) id: number, @Body() dto: UpdateBankCodeDto) { // // update(@Param('id', ParseIntPipe) id: number, @Body() dto: UpdateBankCodeDto) {
// return this.bankCodesService.update(id, dto) // // return this.bankCodesService.update(id, dto)
// } // // }
// @Delete(':id') // // @Delete(':id')
// @ApiOperation({ summary: 'Delete a bank code' }) // // @ApiOperation({ summary: 'Delete a bank code' })
// @ApiNotFoundResponse({ description: 'Bank code not found.' }) // // @ApiNotFoundResponse({ description: 'Bank code not found.' })
// remove(@Param('id', ParseIntPipe) id: number) { // // remove(@Param('id', ParseIntPipe) id: number) {
// return this.bankCodesService.remove(id); // // return this.bankCodesService.remove(id);
// } // // }
} // }

View File

@ -1,46 +1,46 @@
import { ApiProperty } from "@nestjs/swagger"; // import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer"; // import { Type } from "class-transformer";
import { Allow, IsNotEmpty, IsNumber, IsString } from "class-validator"; // import { Allow, IsNotEmpty, IsNumber, IsString } from "class-validator";
export class CreateBankCodeDto { // export class CreateBankCodeDto {
@ApiProperty({ // @ApiProperty({
example: 1, // example: 1,
description: 'Unique ID of a bank-code (auto-generated)', // description: 'Unique ID of a bank-code (auto-generated)',
readOnly: true, // readOnly: true,
}) // })
@Allow() // @Allow()
id: number; // id: number;
@ApiProperty({ // @ApiProperty({
example: 'regular, vacation, emergency, sick, parental, etc', // example: 'regular, vacation, emergency, sick, parental, etc',
description: 'Type of codes', // description: 'Type of codes',
}) // })
@IsString() // @IsString()
@IsNotEmpty() // @IsNotEmpty()
type: string; // type: string;
@ApiProperty({ // @ApiProperty({
example: 'shift, expense, leave', // example: 'shift, expense, leave',
description: 'categorie of the related code', // description: 'categorie of the related code',
}) // })
@IsString() // @IsString()
@IsNotEmpty() // @IsNotEmpty()
categorie: string; // categorie: string;
@ApiProperty({ // @ApiProperty({
example: '0, 0.72, 1, 1.5, 2', // example: '0, 0.72, 1, 1.5, 2',
description: 'modifier number to apply to salary', // description: 'modifier number to apply to salary',
}) // })
@Type(()=> Number) // @Type(()=> Number)
@IsNumber() // @IsNumber()
@IsNotEmpty() // @IsNotEmpty()
modifier: number; // modifier: number;
@ApiProperty({ // @ApiProperty({
example: 'G1, G345, G501, G43, G700', // example: 'G1, G345, G501, G43, G700',
description: 'codes given by the bank', // description: 'codes given by the bank',
}) // })
@IsString() // @IsString()
@IsNotEmpty() // @IsNotEmpty()
bank_code: string; // bank_code: string;
} // }

View File

@ -1,4 +1,4 @@
import { PartialType } from "@nestjs/swagger"; // import { PartialType } from "@nestjs/swagger";
import { CreateBankCodeDto } from "./create-bank-code.dto"; // import { CreateBankCodeDto } from "./create-bank-code.dto";
export class UpdateBankCodeDto extends PartialType(CreateBankCodeDto) {} // export class UpdateBankCodeDto extends PartialType(CreateBankCodeDto) {}

View File

@ -1,51 +1,51 @@
import { Injectable, NotFoundException } from "@nestjs/common"; // import { Injectable, NotFoundException } from "@nestjs/common";
import { PrismaService } from "src/prisma/prisma.service"; // import { PrismaService } from "src/prisma/prisma.service";
import { CreateBankCodeDto } from "../dtos/create-bank-code.dto"; // import { CreateBankCodeDto } from "../dtos/create-bank-code.dto";
import { BankCodes } from "@prisma/client"; // import { BankCodes } from "@prisma/client";
import { UpdateBankCodeDto } from "../dtos/update-bank-code.dto"; // import { UpdateBankCodeDto } from "../dtos/update-bank-code.dto";
@Injectable() // @Injectable()
export class BankCodesService { // export class BankCodesService {
constructor(private readonly prisma: PrismaService) {} // constructor(private readonly prisma: PrismaService) {}
async create(dto: CreateBankCodeDto): Promise<BankCodes>{ // async create(dto: CreateBankCodeDto): Promise<BankCodes>{
return this.prisma.bankCodes.create({ // return this.prisma.bankCodes.create({
data: { // data: {
type: dto.type, // type: dto.type,
categorie: dto.categorie, // categorie: dto.categorie,
modifier: dto.modifier, // modifier: dto.modifier,
bank_code: dto.bank_code, // bank_code: dto.bank_code,
}, // },
}); // });
} // }
findAll() { // findAll() {
return this.prisma.bankCodes.findMany(); // return this.prisma.bankCodes.findMany();
} // }
async findOne(id: number) { // async findOne(id: number) {
const bankCode = await this.prisma.bankCodes.findUnique({ where: {id} }); // const bankCode = await this.prisma.bankCodes.findUnique({ where: {id} });
if(!bankCode) throw new NotFoundException(`Bank Code #${id} not found`); // if(!bankCode) throw new NotFoundException(`Bank Code #${id} not found`);
return bankCode; // return bankCode;
} // }
async update(id:number, dto: UpdateBankCodeDto) { // async update(id:number, dto: UpdateBankCodeDto) {
return await this.prisma.bankCodes.update({ // return await this.prisma.bankCodes.update({
where: { id }, // where: { id },
data: { // data: {
type: dto.type, // type: dto.type,
categorie: dto.categorie, // categorie: dto.categorie,
modifier: dto.modifier as any, // modifier: dto.modifier as any,
bank_code: dto.bank_code, // bank_code: dto.bank_code,
}, // },
}); // });
} // }
async remove(id: number) { // async remove(id: number) {
await this.findOne(id); // await this.findOne(id);
return this.prisma.bankCodes.delete({ where: {id} }); // return this.prisma.bankCodes.delete({ where: {id} });
} // }
} // }

View File

@ -1,79 +1,79 @@
import { ApiProperty } from "@nestjs/swagger"; // import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer"; // import { Type } from "class-transformer";
import { // import {
Allow, // Allow,
IsEmail, // IsEmail,
IsInt, // IsInt,
IsNotEmpty, // IsNotEmpty,
IsOptional, // IsOptional,
IsPositive, // IsPositive,
IsString, // IsString,
IsUUID, // IsUUID,
} from "class-validator"; // } from "class-validator";
export class CreateCustomerDto { // export class CreateCustomerDto {
@ApiProperty({ // @ApiProperty({
example: 1, // example: 1,
description: 'Unique ID of a customer(primary-key, auto-incremented)', // description: 'Unique ID of a customer(primary-key, auto-incremented)',
}) // })
@Allow() // @Allow()
id?: number; // id?: number;
@ApiProperty({ // @ApiProperty({
example: '0e6e2e1f-b157-4c7c-ae3f-999b3e4f914d', // example: '0e6e2e1f-b157-4c7c-ae3f-999b3e4f914d',
description: 'UUID of the user linked to that customer', // description: 'UUID of the user linked to that customer',
}) // })
@IsUUID() // @IsUUID()
@IsOptional() // @IsOptional()
user_id?: string; // user_id?: string;
@ApiProperty({ // @ApiProperty({
example: 'Gandalf', // example: 'Gandalf',
description: 'Customer`s first name', // description: 'Customer`s first name',
}) // })
@IsString() // @IsString()
@IsNotEmpty() // @IsNotEmpty()
first_name: string; // first_name: string;
@ApiProperty({ // @ApiProperty({
example: 'TheGray', // example: 'TheGray',
description: 'Customer`s last name', // description: 'Customer`s last name',
}) // })
@IsString() // @IsString()
@IsNotEmpty() // @IsNotEmpty()
last_name: string; // last_name: string;
@ApiProperty({ // @ApiProperty({
example: 'you_shall_not_pass@middleEarth.com', // example: 'you_shall_not_pass@middleEarth.com',
description: 'Customer`s email', // description: 'Customer`s email',
}) // })
@IsEmail() // @IsEmail()
@IsOptional() // @IsOptional()
email: string; // email: string;
@ApiProperty({ // @ApiProperty({
example: '8436637464', // example: '8436637464',
description: 'Customer`s phone number', // description: 'Customer`s phone number',
}) // })
@IsString() // @IsString()
phone_number: string; // phone_number: string;
@ApiProperty({ // @ApiProperty({
example: '1 Ringbearer`s way, Mount Doom city, ME, T1R 1N6 ', // example: '1 Ringbearer`s way, Mount Doom city, ME, T1R 1N6 ',
description: 'Customer`s residence', // description: 'Customer`s residence',
required: false, // required: false,
}) // })
@IsString() // @IsString()
@IsOptional() // @IsOptional()
residence?: string; // residence?: string;
@ApiProperty({ // @ApiProperty({
example: '4263253', // example: '4263253',
description: 'Customer`s invoice number', // description: 'Customer`s invoice number',
required: false, // required: false,
}) // })
@Type(() => Number) // @Type(() => Number)
@IsInt() // @IsInt()
@IsNotEmpty() // @IsNotEmpty()
invoice_id: number; // invoice_id: number;
} // }

View File

@ -1,4 +1,4 @@
import { PartialType } from "@nestjs/swagger"; // import { PartialType } from "@nestjs/swagger";
import { CreateCustomerDto } from "./create-customer.dto"; // import { CreateCustomerDto } from "./create-customer.dto";
export class UpdateCustomerDto extends PartialType(CreateCustomerDto) {} // export class UpdateCustomerDto extends PartialType(CreateCustomerDto) {}

View File

@ -1,93 +1,93 @@
import { Injectable } from '@nestjs/common'; // import { Injectable } from '@nestjs/common';
@Injectable() // @Injectable()
export class CustomersService { // export class CustomersService {
//_____________________________________________________________________________________________ // //_____________________________________________________________________________________________
// Deprecated or unused methods // // Deprecated or unused methods
//_____________________________________________________________________________________________ // //_____________________________________________________________________________________________
// constructor(private readonly prisma: PrismaService) {} // // constructor(private readonly prisma: PrismaService) {}
// async create(dto: CreateCustomerDto): Promise<Customers> { // // async create(dto: CreateCustomerDto): Promise<Customers> {
// const { // // const {
// first_name, // // first_name,
// last_name, // // last_name,
// email, // // email,
// phone_number, // // phone_number,
// residence, // // residence,
// invoice_id, // // invoice_id,
// } = dto; // // } = dto;
// return this.prisma.$transaction(async (transaction) => { // // return this.prisma.$transaction(async (transaction) => {
// const user: Users = await transaction.users.create({ // // const user: Users = await transaction.users.create({
// data: { // // data: {
// first_name, // // first_name,
// last_name, // // last_name,
// email, // // email,
// phone_number, // // phone_number,
// residence, // // residence,
// }, // // },
// }); // // });
// return transaction.customers.create({ // // return transaction.customers.create({
// data: { // // data: {
// user_id: user.id, // // user_id: user.id,
// invoice_id, // // invoice_id,
// }, // // },
// }); // // });
// }); // // });
// } // // }
// findAll(): Promise<Customers[]> { // // findAll(): Promise<Customers[]> {
// return this.prisma.customers.findMany({ // // return this.prisma.customers.findMany({
// include: { user: true }, // // include: { user: true },
// }) // // })
// } // // }
// async findOne(id:number): Promise<Customers> { // // async findOne(id:number): Promise<Customers> {
// const customer = await this.prisma.customers.findUnique({ // // const customer = await this.prisma.customers.findUnique({
// where: { id }, // // where: { id },
// include: { user: true }, // // include: { user: true },
// }); // // });
// if(!customer) throw new NotFoundException(`Customer #${id} not found`); // // if(!customer) throw new NotFoundException(`Customer #${id} not found`);
// return customer; // // return customer;
// } // // }
// async update(id: number,dto: UpdateCustomerDto): Promise<Customers> { // // async update(id: number,dto: UpdateCustomerDto): Promise<Customers> {
// const customer = await this.findOne(id); // // const customer = await this.findOne(id);
// const { // // const {
// first_name, // // first_name,
// last_name, // // last_name,
// email, // // email,
// phone_number, // // phone_number,
// residence, // // residence,
// invoice_id, // // invoice_id,
// } = dto; // // } = dto;
// return this.prisma.$transaction(async (transaction) => { // // return this.prisma.$transaction(async (transaction) => {
// await transaction.users.update({ // // await transaction.users.update({
// where: { id: customer.user_id }, // // where: { id: customer.user_id },
// data: { // // data: {
// ...(first_name !== undefined && { first_name }), // // ...(first_name !== undefined && { first_name }),
// ...(last_name !== undefined && { last_name }), // // ...(last_name !== undefined && { last_name }),
// ...(email !== undefined && { email }), // // ...(email !== undefined && { email }),
// ...(phone_number !== undefined && { phone_number }), // // ...(phone_number !== undefined && { phone_number }),
// ...(residence !== undefined && { residence }), // // ...(residence !== undefined && { residence }),
// }, // // },
// }); // // });
// return transaction.customers.update({ // // return transaction.customers.update({
// where: { id }, // // where: { id },
// data: { // // data: {
// ...(invoice_id !== undefined && { invoice_id }), // // ...(invoice_id !== undefined && { invoice_id }),
// }, // // },
// }); // // });
// }); // // });
// // }
// // async remove(id: number): Promise<Customers> {
// // await this.findOne(id);
// // return this.prisma.customers.delete({ where: { id }});
// // }
// } // }
// async remove(id: number): Promise<Customers> {
// await this.findOne(id);
// return this.prisma.customers.delete({ where: { id }});
// }
}

View File

@ -1,118 +1,118 @@
import { // import {
Allow, // Allow,
IsBoolean, // IsBoolean,
IsDateString, // IsDateString,
IsEmail, // IsEmail,
IsInt, // IsInt,
IsNotEmpty, // IsNotEmpty,
IsOptional, // IsOptional,
IsPositive, // IsPositive,
IsString, // IsString,
IsUUID, // IsUUID,
} from 'class-validator'; // } from 'class-validator';
import { Type } from 'class-transformer'; // import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger'; // import { ApiProperty } from '@nestjs/swagger';
export class CreateEmployeeDto { // export class CreateEmployeeDto {
@ApiProperty({ // @ApiProperty({
example: 1, // example: 1,
description: 'Unique ID of an employee(primary-key, auto-incremented)', // description: 'Unique ID of an employee(primary-key, auto-incremented)',
}) // })
@Allow() // @Allow()
id: number; // id: number;
@ApiProperty({ // @ApiProperty({
example: '0e6e2e1f-b157-4c7c-ae3f-999b3e4f914d', // example: '0e6e2e1f-b157-4c7c-ae3f-999b3e4f914d',
description: 'UUID of the user linked to that employee', // description: 'UUID of the user linked to that employee',
}) // })
@IsUUID() // @IsUUID()
@IsOptional() // @IsOptional()
user_id?: string; // user_id?: string;
@ApiProperty({ // @ApiProperty({
example: 'Frodo', // example: 'Frodo',
description: 'Employee`s first name', // description: 'Employee`s first name',
}) // })
@IsString() // @IsString()
@IsNotEmpty() // @IsNotEmpty()
first_name: string; // first_name: string;
@ApiProperty({ // @ApiProperty({
example: 'Baggins', // example: 'Baggins',
description: 'Employee`s last name', // description: 'Employee`s last name',
}) // })
@IsString() // @IsString()
@IsNotEmpty() // @IsNotEmpty()
last_name: string; // last_name: string;
@ApiProperty({ // @ApiProperty({
example: 'i_cant_do_this_sam@targointernet.com', // example: 'i_cant_do_this_sam@targointernet.com',
description: 'Employee`s email', // description: 'Employee`s email',
}) // })
@IsEmail() // @IsEmail()
@IsOptional() // @IsOptional()
email: string; // email: string;
@IsOptional() // @IsOptional()
@IsBoolean() // @IsBoolean()
is_supervisor: boolean; // is_supervisor: boolean;
@ApiProperty({ // @ApiProperty({
example: '82538437464', // example: '82538437464',
description: 'Employee`s phone number', // description: 'Employee`s phone number',
}) // })
@IsString() // @IsString()
phone_number: string; // phone_number: string;
@ApiProperty({ // @ApiProperty({
example: '1 Bagshot Row, Hobbiton, The Shire, Middle-earth', // example: '1 Bagshot Row, Hobbiton, The Shire, Middle-earth',
description: 'Employee`s residence', // description: 'Employee`s residence',
required: false, // required: false,
}) // })
@IsString() // @IsString()
@IsOptional() // @IsOptional()
residence?: string; // residence?: string;
@ApiProperty({ // @ApiProperty({
example: 7464, // example: 7464,
description: 'external ID for the pay system', // description: 'external ID for the pay system',
}) // })
@IsInt() // @IsInt()
@IsPositive() // @IsPositive()
@Type(() => Number) // @Type(() => Number)
external_payroll_id: number; // external_payroll_id: number;
@ApiProperty({ // @ApiProperty({
example: 335567447, // example: 335567447,
description: 'Employee`s company code', // description: 'Employee`s company code',
}) // })
@IsInt() // @IsInt()
@IsPositive() // @IsPositive()
@Type(() => Number) // @Type(() => Number)
company_code: number; // company_code: number;
@ApiProperty({ // @ApiProperty({
example:'technicient', // example:'technicient',
description: 'employee`s job title', // description: 'employee`s job title',
}) // })
@IsString() // @IsString()
@IsOptional() // @IsOptional()
job_title: string; // job_title: string;
@ApiProperty({ // @ApiProperty({
example: '23/09/3018', // example: '23/09/3018',
description: 'Employee`s first working day', // description: 'Employee`s first working day',
}) // })
@IsDateString() // @IsDateString()
first_work_day: string; // first_work_day: string;
@ApiProperty({ // @ApiProperty({
example: '25/03/3019', // example: '25/03/3019',
description: 'Employee`s last working day', // description: 'Employee`s last working day',
required: false, // required: false,
}) // })
@IsDateString() // @IsDateString()
@IsOptional() // @IsOptional()
last_work_day?: string; // last_work_day?: string;
} // }

View File

@ -1,8 +1,8 @@
export class EmployeeListItemDto { // export class EmployeeListItemDto {
first_name: string; // first_name: string;
last_name: string; // last_name: string;
email: 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;
} // }

View File

@ -1,13 +1,13 @@
export class EmployeeProfileItemDto { // export class EmployeeProfileItemDto {
first_name: string; // first_name: string;
last_name: string; // last_name: string;
employee_full_name: string; // employee_full_name: 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;
email: string | null; // email: string | null;
phone_number: string; // phone_number: string;
first_work_day: string; // first_work_day: string;
last_work_day?: string | null; // last_work_day?: string | null;
residence: string | null; // residence: string | null;
} // }

View File

@ -1,22 +1,22 @@
import { ApiProperty, PartialType } from '@nestjs/swagger'; // import { ApiProperty, PartialType } from '@nestjs/swagger';
import { CreateEmployeeDto } from './create-employee.dto'; // import { CreateEmployeeDto } from './create-employee.dto';
import { IsDateString, IsOptional, Max } from 'class-validator'; // import { IsDateString, IsOptional, Max } from 'class-validator';
export class UpdateEmployeeDto extends PartialType(CreateEmployeeDto) { // export class UpdateEmployeeDto extends PartialType(CreateEmployeeDto) {
@ApiProperty({ required: false, type: Date, description: 'New hire date or undefined' }) // @ApiProperty({ required: false, type: Date, description: 'New hire date or undefined' })
@IsDateString() // @IsDateString()
@IsOptional() // @IsOptional()
first_work_day?: string; // first_work_day?: string;
@ApiProperty({ required: false, type: Date, description: 'Termination date (null to restore)' }) // @ApiProperty({ required: false, type: Date, description: 'Termination date (null to restore)' })
@IsDateString() // @IsDateString()
@IsOptional() // @IsOptional()
last_work_day?: string; // last_work_day?: string;
@ApiProperty({ required: false, type: Number, description: 'Supervisor ID' }) // @ApiProperty({ required: false, type: Number, description: 'Supervisor ID' })
@IsOptional() // @IsOptional()
supervisor_id?: number; // supervisor_id?: number;
@IsOptional() // @IsOptional()
phone_number: string; // phone_number: string;
} // }

View File

@ -1,230 +1,230 @@
import { Injectable, NotFoundException } from '@nestjs/common'; // import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service'; // import { PrismaService } from 'src/prisma/prisma.service';
import { EmployeeListItemDto } from '../dtos/list-employee.dto'; // import { EmployeeListItemDto } from '../dtos/list-employee.dto';
import { EmployeeProfileItemDto } from '../dtos/profil-employee.dto'; // import { EmployeeProfileItemDto } from '../dtos/profil-employee.dto';
@Injectable() // @Injectable()
export class EmployeesService { // export class EmployeesService {
constructor(private readonly prisma: PrismaService) { } // constructor(private readonly prisma: PrismaService) { }
findListEmployees(): Promise<EmployeeListItemDto[]> { // findListEmployees(): Promise<EmployeeListItemDto[]> {
return this.prisma.employees.findMany({ // return this.prisma.employees.findMany({
select: { // select: {
user: { // user: {
select: { // select: {
first_name: true, // first_name: true,
last_name: true, // last_name: true,
email: true, // email: true,
}, // },
}, // },
supervisor: { // supervisor: {
select: { // select: {
user: { // user: {
select: { // select: {
first_name: true, // first_name: true,
last_name: true, // last_name: true,
}, // },
}, // },
}, // },
}, // },
job_title: true, // job_title: true,
company_code: true, // company_code: true,
} // }
}).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, // email: r.user.email,
company_name: r.company_code, // company_name: r.company_code,
job_title: r.job_title, // job_title: r.job_title,
employee_full_name: `${r.user.first_name} ${r.user.last_name}`, // employee_full_name: `${r.user.first_name} ${r.user.last_name}`,
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,
})), // })),
); // );
} // }
async findOneProfile(email: string): Promise<EmployeeProfileItemDto> { // async findOneProfile(email: string): Promise<EmployeeProfileItemDto> {
const emp = await this.prisma.employees.findFirst({ // const emp = await this.prisma.employees.findFirst({
where: { user: { email } }, // where: { user: { email } },
select: { // select: {
user: { // user: {
select: { // select: {
first_name: true, // first_name: true,
last_name: true, // last_name: true,
email: true, // email: true,
phone_number: true, // phone_number: true,
residence: true, // residence: true,
}, // },
}, // },
supervisor: { // supervisor: {
select: { // select: {
user: { // user: {
select: { // select: {
first_name: true, // first_name: true,
last_name: true, // last_name: true,
}, // },
}, // },
}, // },
}, // },
job_title: true, // job_title: true,
company_code: true, // company_code: true,
first_work_day: true, // first_work_day: true,
last_work_day: true, // last_work_day: true,
} // }
}); // });
if (!emp) throw new NotFoundException(`Employee with email ${email} not found`); // if (!emp) throw new NotFoundException(`Employee with email ${email} not found`);
return { // return {
first_name: emp.user.first_name, // first_name: emp.user.first_name,
last_name: emp.user.last_name, // last_name: emp.user.last_name,
email: emp.user.email, // email: emp.user.email,
residence: emp.user.residence, // residence: emp.user.residence,
phone_number: emp.user.phone_number, // phone_number: emp.user.phone_number,
company_name: emp.company_code, // company_name: emp.company_code,
job_title: emp.job_title, // job_title: emp.job_title,
employee_full_name: `${emp.user.first_name} ${emp.user.last_name}`, // employee_full_name: `${emp.user.first_name} ${emp.user.last_name}`,
first_work_day: emp.first_work_day.toISOString().slice(0, 10), // 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, // last_work_day: emp.last_work_day ? emp.last_work_day.toISOString().slice(0, 10) : null,
supervisor_full_name: emp.supervisor ? `${emp.supervisor.user.first_name}, ${emp.supervisor.user.last_name}` : null, // supervisor_full_name: emp.supervisor ? `${emp.supervisor.user.first_name}, ${emp.supervisor.user.last_name}` : null,
}; // };
} // }
//_____________________________________________________________________________________________ // //_____________________________________________________________________________________________
// Deprecated or unused methods // // Deprecated or unused methods
//_____________________________________________________________________________________________ // //_____________________________________________________________________________________________
// async create(dto: CreateEmployeeDto): Promise<Employees> { // // async create(dto: CreateEmployeeDto): Promise<Employees> {
// const { // // const {
// first_name, // // first_name,
// last_name, // // last_name,
// email, // // email,
// phone_number, // // phone_number,
// residence, // // residence,
// external_payroll_id, // // external_payroll_id,
// company_code, // // company_code,
// job_title, // // job_title,
// first_work_day, // // first_work_day,
// last_work_day, // // last_work_day,
// is_supervisor, // // is_supervisor,
// } = dto; // // } = dto;
// return this.prisma.$transaction(async (transaction) => { // // return this.prisma.$transaction(async (transaction) => {
// const user: Users = await transaction.users.create({ // // const user: Users = await transaction.users.create({
// data: { // // data: {
// first_name, // // first_name,
// last_name, // // last_name,
// email, // // email,
// phone_number, // // phone_number,
// residence, // // residence,
// }, // // },
// }); // // });
// return transaction.employees.create({ // // return transaction.employees.create({
// data: { // // data: {
// user_id: user.id, // // user_id: user.id,
// external_payroll_id, // // external_payroll_id,
// company_code, // // company_code,
// job_title, // // job_title,
// first_work_day, // // first_work_day,
// last_work_day, // // last_work_day,
// is_supervisor, // // is_supervisor,
// }, // // },
// }); // // });
// }); // // });
// } // // }
// findAll(): Promise<Employees[]> { // // findAll(): Promise<Employees[]> {
// return this.prisma.employees.findMany({ // // return this.prisma.employees.findMany({
// include: { user: true }, // // include: { user: true },
// }); // // });
// } // // }
// async findOne(email: string): Promise<Employees> { // // async findOne(email: string): Promise<Employees> {
// const emp = await this.prisma.employees.findFirst({ // // const emp = await this.prisma.employees.findFirst({
// where: { user: { email } }, // // where: { user: { email } },
// include: { user: true }, // // include: { user: true },
// }); // // });
// //add search for archived employees // // //add search for archived employees
// if (!emp) { // // if (!emp) {
// throw new NotFoundException(`Employee with email: ${email} not found`); // // throw new NotFoundException(`Employee with email: ${email} not found`);
// } // // }
// return emp; // // return emp;
// } // // }
// async update( // // async update(
// email: string, // // email: string,
// dto: UpdateEmployeeDto, // // dto: UpdateEmployeeDto,
// ): Promise<Employees> { // // ): Promise<Employees> {
// const emp = await this.findOne(email); // // const emp = await this.findOne(email);
// const { // // const {
// first_name, // // first_name,
// last_name, // // last_name,
// phone_number, // // phone_number,
// residence, // // residence,
// external_payroll_id, // // external_payroll_id,
// company_code, // // company_code,
// job_title, // // job_title,
// first_work_day, // // first_work_day,
// last_work_day, // // last_work_day,
// is_supervisor, // // is_supervisor,
// email: new_email, // // email: new_email,
// } = dto; // // } = dto;
// return this.prisma.$transaction(async (transaction) => { // // return this.prisma.$transaction(async (transaction) => {
// if( // // if(
// first_name !== undefined || // // first_name !== undefined ||
// last_name !== undefined || // // last_name !== undefined ||
// new_email !== undefined || // // new_email !== undefined ||
// phone_number !== undefined || // // phone_number !== undefined ||
// residence !== undefined // // residence !== undefined
// ){ // // ){
// await transaction.users.update({ // // await transaction.users.update({
// where: { id: emp.user_id }, // // where: { id: emp.user_id },
// data: { // // data: {
// ...(first_name !== undefined && { first_name }), // // ...(first_name !== undefined && { first_name }),
// ...(last_name !== undefined && { last_name }), // // ...(last_name !== undefined && { last_name }),
// ...(email !== undefined && { email }), // // ...(email !== undefined && { email }),
// ...(phone_number !== undefined && { phone_number }), // // ...(phone_number !== undefined && { phone_number }),
// ...(residence !== undefined && { residence }), // // ...(residence !== undefined && { residence }),
// }, // // },
// }); // // });
// } // // }
// const updated = await transaction.employees.update({ // // const updated = await transaction.employees.update({
// where: { id: emp.id }, // // where: { id: emp.id },
// data: { // // data: {
// ...(external_payroll_id !== undefined && { external_payroll_id }), // // ...(external_payroll_id !== undefined && { external_payroll_id }),
// ...(company_code !== undefined && { company_code }), // // ...(company_code !== undefined && { company_code }),
// ...(first_work_day !== undefined && { first_work_day }), // // ...(first_work_day !== undefined && { first_work_day }),
// ...(last_work_day !== undefined && { last_work_day }), // // ...(last_work_day !== undefined && { last_work_day }),
// ...(job_title !== undefined && { job_title }), // // ...(job_title !== undefined && { job_title }),
// ...(is_supervisor !== undefined && { is_supervisor }), // // ...(is_supervisor !== undefined && { is_supervisor }),
// }, // // },
// }); // // });
// return updated; // // return updated;
// }); // // });
// } // // }
// async remove(email: string): Promise<Employees> { // // async remove(email: string): Promise<Employees> {
// const emp = await this.findOne(email); // // const emp = await this.findOne(email);
// return this.prisma.$transaction(async (transaction) => { // // return this.prisma.$transaction(async (transaction) => {
// await transaction.employees.updateMany({ // // await transaction.employees.updateMany({
// where: { supervisor_id: emp.id }, // // where: { supervisor_id: emp.id },
// data: { supervisor_id: null }, // // data: { supervisor_id: null },
// }); // // });
// const deleted_employee = await transaction.employees.delete({ // // const deleted_employee = await transaction.employees.delete({
// where: {id: emp.id }, // // where: {id: emp.id },
// }); // // });
// await transaction.users.delete({ // // await transaction.users.delete({
// where: { id: emp.user_id }, // // where: { id: emp.user_id },
// }); // // });
// return deleted_employee; // // return deleted_employee;
// }); // // });
// } // // }
} // }

View File

@ -1,9 +1,9 @@
export function toDateOrNull(v?: string | null): Date | null { // export function toDateOrNull(v?: string | null): Date | null {
if (!v) return null; // if (!v) return null;
const day = new Date(v); // const day = new Date(v);
return isNaN(day.getTime()) ? null : day; // return isNaN(day.getTime()) ? null : day;
} // }
export function toDateOrUndefined(v?: string | null): Date | undefined { // export function toDateOrUndefined(v?: string | null): Date | undefined {
const day = toDateOrNull(v ?? undefined); // const day = toDateOrNull(v ?? undefined);
return day === null ? undefined : day; // return day === null ? undefined : day;
} // }