refactor(cleaning): preparing other modules for refactoring
This commit is contained in:
parent
1289aed720
commit
2712033451
|
|
@ -14,48 +14,48 @@ datasource db {
|
|||
url = env("DATABASE_URL_DEV")
|
||||
}
|
||||
|
||||
model Users {
|
||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
first_name String
|
||||
last_name String
|
||||
email String @unique
|
||||
phone_number String @unique
|
||||
residence String?
|
||||
role Roles @default(GUEST)
|
||||
// model Users {
|
||||
// id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
// first_name String
|
||||
// last_name String
|
||||
// email String @unique
|
||||
// phone_number String @unique
|
||||
// residence String?
|
||||
// role Roles @default(GUEST)
|
||||
|
||||
employee Employees? @relation("UserEmployee")
|
||||
oauth_sessions OAuthSessions[] @relation("UserOAuthSessions")
|
||||
preferences Preferences? @relation("UserPreferences")
|
||||
// employee Employees? @relation("UserEmployee")
|
||||
// oauth_sessions OAuthSessions[] @relation("UserOAuthSessions")
|
||||
// preferences Preferences? @relation("UserPreferences")
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
// @@map("users")
|
||||
// }
|
||||
|
||||
model Employees {
|
||||
id Int @id @default(autoincrement())
|
||||
user Users @relation("UserEmployee", fields: [user_id], references: [id])
|
||||
user_id String @unique @db.Uuid
|
||||
supervisor Employees? @relation("EmployeeSupervisor", fields: [supervisor_id], references: [id])
|
||||
supervisor_id Int?
|
||||
// model Employees {
|
||||
// id Int @id @default(autoincrement())
|
||||
// user Users @relation("UserEmployee", fields: [user_id], references: [id])
|
||||
// user_id String @unique @db.Uuid
|
||||
// supervisor Employees? @relation("EmployeeSupervisor", fields: [supervisor_id], references: [id])
|
||||
// supervisor_id Int?
|
||||
|
||||
external_payroll_id Int
|
||||
company_code Int
|
||||
first_work_day DateTime @db.Date
|
||||
last_work_day DateTime? @db.Date
|
||||
job_title String?
|
||||
is_supervisor Boolean @default(false)
|
||||
// external_payroll_id Int
|
||||
// company_code Int
|
||||
// first_work_day DateTime @db.Date
|
||||
// last_work_day DateTime? @db.Date
|
||||
// job_title String?
|
||||
// is_supervisor Boolean @default(false)
|
||||
|
||||
|
||||
crew Employees[] @relation("EmployeeSupervisor")
|
||||
timesheet Timesheets[] @relation("TimesheetEmployee")
|
||||
leave_request LeaveRequests[] @relation("LeaveRequestEmployee")
|
||||
schedule_presets SchedulePresets[] @relation("SchedulePreset")
|
||||
// crew Employees[] @relation("EmployeeSupervisor")
|
||||
// timesheet Timesheets[] @relation("TimesheetEmployee")
|
||||
// leave_request LeaveRequests[] @relation("LeaveRequestEmployee")
|
||||
// schedule_presets SchedulePresets[] @relation("SchedulePreset")
|
||||
|
||||
@@map("employees")
|
||||
}
|
||||
// @@map("employees")
|
||||
// }
|
||||
|
||||
model LeaveRequests {
|
||||
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
|
||||
bank_code BankCodes @relation("LeaveRequestBankCodes", fields: [bank_code_id], references: [id])
|
||||
bank_code_id Int
|
||||
|
|
@ -107,7 +107,7 @@ view PayPeriods {
|
|||
|
||||
model Timesheets {
|
||||
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
|
||||
|
||||
start_date DateTime @db.Date
|
||||
|
|
@ -135,7 +135,7 @@ model TimesheetsArchive {
|
|||
|
||||
model SchedulePresets {
|
||||
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
|
||||
|
||||
name String
|
||||
|
|
@ -258,7 +258,7 @@ model ExpensesArchive {
|
|||
|
||||
model OAuthSessions {
|
||||
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
|
||||
application String
|
||||
access_token String @unique
|
||||
|
|
@ -327,7 +327,7 @@ model AttachmentVariants {
|
|||
|
||||
model Preferences {
|
||||
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
|
||||
|
||||
notifications Int @default(0)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { AppController } from './app.controller';
|
|||
import { AppService } from './app.service';
|
||||
// import { ArchivalModule } from './modules/archival/archival.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 { HealthModule } from './health/health.module';
|
||||
import { HealthController } from './health/health.controller';
|
||||
|
|
@ -23,7 +23,7 @@ import { TimeAndAttendanceModule } from 'src/time-and-attendance/time-and-attend
|
|||
@Module({
|
||||
imports: [
|
||||
AuthenticationModule,
|
||||
BankCodesModule,
|
||||
// BankCodesModule,
|
||||
ConfigModule.forRoot({isGlobal: true}),
|
||||
// CsvExportModule,
|
||||
// CustomersModule,
|
||||
|
|
|
|||
|
|
@ -1,32 +1,32 @@
|
|||
import { UseGuards, Controller, Get, Param, ParseIntPipe, NotFoundException } from "@nestjs/common";
|
||||
import { ApiTags, ApiOperation, ApiResponse } from "@nestjs/swagger";
|
||||
import { ExpensesArchive,Roles as RoleEnum } from "@prisma/client";
|
||||
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
||||
import { ExpensesArchivalService } from "src/time-and-attendance/modules/expenses/services/expenses-archival.service";
|
||||
// import { UseGuards, Controller, Get, Param, ParseIntPipe, NotFoundException } from "@nestjs/common";
|
||||
// import { ApiTags, ApiOperation, ApiResponse } from "@nestjs/swagger";
|
||||
// import { ExpensesArchive,Roles as RoleEnum } from "@prisma/client";
|
||||
// import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
||||
// import { ExpensesArchivalService } from "src/time-and-attendance/modules/expenses/services/expenses-archival.service";
|
||||
|
||||
@ApiTags('Expense Archives')
|
||||
// @UseGuards()
|
||||
@Controller('archives/expenses')
|
||||
export class ExpensesArchiveController {
|
||||
constructor(private readonly expensesService: ExpensesArchivalService) {}
|
||||
// @ApiTags('Expense Archives')
|
||||
// // @UseGuards()
|
||||
// @Controller('archives/expenses')
|
||||
// export class ExpensesArchiveController {
|
||||
// constructor(private readonly expensesService: ExpensesArchivalService) {}
|
||||
|
||||
@Get()
|
||||
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
@ApiOperation({ summary: 'List of archived expenses'})
|
||||
@ApiResponse({ status: 200, description: 'List of archived expenses', isArray: true })
|
||||
async findAllArchived(): Promise<ExpensesArchive[]> {
|
||||
return this.expensesService.findAllArchived();
|
||||
}
|
||||
// @Get()
|
||||
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
// @ApiOperation({ summary: 'List of archived expenses'})
|
||||
// @ApiResponse({ status: 200, description: 'List of archived expenses', isArray: true })
|
||||
// async findAllArchived(): Promise<ExpensesArchive[]> {
|
||||
// return this.expensesService.findAllArchived();
|
||||
// }
|
||||
|
||||
@Get()
|
||||
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
@ApiOperation({ summary: 'Fetch expense in archives with its Id'})
|
||||
@ApiResponse({ status: 200, description: 'Archived expense found'})
|
||||
async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<ExpensesArchive> {
|
||||
try{
|
||||
return await this.expensesService.findOneArchived(id);
|
||||
}catch {
|
||||
throw new NotFoundException(`Archived expense #${id} not found`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// @Get()
|
||||
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
// @ApiOperation({ summary: 'Fetch expense in archives with its Id'})
|
||||
// @ApiResponse({ status: 200, description: 'Archived expense found'})
|
||||
// async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<ExpensesArchive> {
|
||||
// try{
|
||||
// return await this.expensesService.findOneArchived(id);
|
||||
// }catch {
|
||||
// throw new NotFoundException(`Archived expense #${id} not found`);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { Controller } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
// import { Controller } from '@nestjs/common';
|
||||
// import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('LeaveRequests Archives')
|
||||
// @UseGuards()
|
||||
@Controller('archives/leaveRequests')
|
||||
export class LeaveRequestsArchiveController {}
|
||||
// @ApiTags('LeaveRequests Archives')
|
||||
// // @UseGuards()
|
||||
// @Controller('archives/leaveRequests')
|
||||
// export class LeaveRequestsArchiveController {}
|
||||
|
|
@ -1,32 +1,32 @@
|
|||
import { Get, Param, ParseIntPipe, NotFoundException, Controller, UseGuards } from "@nestjs/common";
|
||||
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
||||
import { ShiftsArchive, Roles as RoleEnum } from "@prisma/client";
|
||||
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
||||
import { ShiftsArchivalService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-archival.service";
|
||||
// import { Get, Param, ParseIntPipe, NotFoundException, Controller, UseGuards } from "@nestjs/common";
|
||||
// import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
||||
// import { ShiftsArchive, Roles as RoleEnum } from "@prisma/client";
|
||||
// import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
||||
// import { ShiftsArchivalService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-archival.service";
|
||||
|
||||
@ApiTags('Shift Archives')
|
||||
// @UseGuards()
|
||||
@Controller('archives/shifts')
|
||||
export class ShiftsArchiveController {
|
||||
constructor(private readonly shiftsService: ShiftsArchivalService) {}
|
||||
// @ApiTags('Shift Archives')
|
||||
// // @UseGuards()
|
||||
// @Controller('archives/shifts')
|
||||
// export class ShiftsArchiveController {
|
||||
// constructor(private readonly shiftsService: ShiftsArchivalService) {}
|
||||
|
||||
@Get()
|
||||
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
@ApiOperation({ summary: 'List of archived shifts'})
|
||||
@ApiResponse({ status: 200, description: 'List of archived shifts', isArray: true })
|
||||
async findAllArchived(): Promise<ShiftsArchive[]> {
|
||||
return this.shiftsService.findAllArchived();
|
||||
}
|
||||
// @Get()
|
||||
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
// @ApiOperation({ summary: 'List of archived shifts'})
|
||||
// @ApiResponse({ status: 200, description: 'List of archived shifts', isArray: true })
|
||||
// async findAllArchived(): Promise<ShiftsArchive[]> {
|
||||
// return this.shiftsService.findAllArchived();
|
||||
// }
|
||||
|
||||
@Get()
|
||||
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR,RoleEnum.SUPERVISOR)
|
||||
@ApiOperation({ summary: 'Fetch shift in archives with its Id'})
|
||||
@ApiResponse({ status: 200, description: 'Archived shift found'})
|
||||
async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<ShiftsArchive> {
|
||||
try{
|
||||
return await this.shiftsService.findOneArchived(id);
|
||||
}catch {
|
||||
throw new NotFoundException(`Archived shift #${id} not found`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// @Get()
|
||||
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR,RoleEnum.SUPERVISOR)
|
||||
// @ApiOperation({ summary: 'Fetch shift in archives with its Id'})
|
||||
// @ApiResponse({ status: 200, description: 'Archived shift found'})
|
||||
// async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<ShiftsArchive> {
|
||||
// try{
|
||||
// return await this.shiftsService.findOneArchived(id);
|
||||
// }catch {
|
||||
// throw new NotFoundException(`Archived shift #${id} not found`);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
@ -1,33 +1,33 @@
|
|||
import { Controller, Get, NotFoundException, Param, ParseIntPipe, UseGuards } from "@nestjs/common";
|
||||
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
||||
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
||||
import { TimesheetsArchive, Roles as RoleEnum } from '@prisma/client';
|
||||
import { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service";
|
||||
// import { Controller, Get, NotFoundException, Param, ParseIntPipe, UseGuards } from "@nestjs/common";
|
||||
// import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
||||
// import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
||||
// import { TimesheetsArchive, Roles as RoleEnum } from '@prisma/client';
|
||||
// import { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service";
|
||||
|
||||
@ApiTags('Timesheet Archives')
|
||||
// @UseGuards()
|
||||
@Controller('archives/timesheets')
|
||||
export class TimesheetsArchiveController {
|
||||
constructor(private readonly timesheetsService: TimesheetArchiveService) {}
|
||||
// @ApiTags('Timesheet Archives')
|
||||
// // @UseGuards()
|
||||
// @Controller('archives/timesheets')
|
||||
// export class TimesheetsArchiveController {
|
||||
// constructor(private readonly timesheetsService: TimesheetArchiveService) {}
|
||||
|
||||
@Get()
|
||||
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
@ApiOperation({ summary: 'List of archived timesheets'})
|
||||
@ApiResponse({ status: 200, description: 'List of archived timesheets', isArray: true })
|
||||
async findAllArchived(): Promise<TimesheetsArchive[]> {
|
||||
return this.timesheetsService.findAllArchived();
|
||||
}
|
||||
// @Get()
|
||||
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
// @ApiOperation({ summary: 'List of archived timesheets'})
|
||||
// @ApiResponse({ status: 200, description: 'List of archived timesheets', isArray: true })
|
||||
// async findAllArchived(): Promise<TimesheetsArchive[]> {
|
||||
// return this.timesheetsService.findAllArchived();
|
||||
// }
|
||||
|
||||
@Get()
|
||||
//@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
@ApiOperation({ summary: 'Fetch timesheet in archives with its Id'})
|
||||
@ApiResponse({ status: 200, description: 'Archived timesheet found'})
|
||||
async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<TimesheetsArchive> {
|
||||
try{
|
||||
return await this.timesheetsService.findOneArchived(id);
|
||||
}catch {
|
||||
throw new NotFoundException(`Archived timesheet #${id} not found`);
|
||||
}
|
||||
}
|
||||
// @Get()
|
||||
// //@RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR)
|
||||
// @ApiOperation({ summary: 'Fetch timesheet in archives with its Id'})
|
||||
// @ApiResponse({ status: 200, description: 'Archived timesheet found'})
|
||||
// async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise<TimesheetsArchive> {
|
||||
// try{
|
||||
// return await this.timesheetsService.findOneArchived(id);
|
||||
// }catch {
|
||||
// throw new NotFoundException(`Archived timesheet #${id} not found`);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
|
@ -1,38 +1,38 @@
|
|||
import { Injectable, Logger } from "@nestjs/common";
|
||||
import { Cron } from "@nestjs/schedule";
|
||||
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 { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service";
|
||||
// import { Injectable, Logger } from "@nestjs/common";
|
||||
// import { Cron } from "@nestjs/schedule";
|
||||
// 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 { TimesheetArchiveService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service";
|
||||
|
||||
@Injectable()
|
||||
export class ArchivalService {
|
||||
private readonly logger = new Logger(ArchivalService.name);
|
||||
// @Injectable()
|
||||
// export class ArchivalService {
|
||||
// private readonly logger = new Logger(ArchivalService.name);
|
||||
|
||||
constructor(
|
||||
private readonly timesheetsService: TimesheetArchiveService,
|
||||
private readonly expensesService: ExpensesArchivalService,
|
||||
private readonly shiftsService: ShiftsArchivalService,
|
||||
) {}
|
||||
// constructor(
|
||||
// private readonly timesheetsService: TimesheetArchiveService,
|
||||
// private readonly expensesService: ExpensesArchivalService,
|
||||
// private readonly shiftsService: ShiftsArchivalService,
|
||||
// ) {}
|
||||
|
||||
@Cron('0 0 3 * * 1', {timeZone:'America/Toronto'}) // chaque premier lundi du mois à 03h00
|
||||
async handleMonthlyArchival() {
|
||||
const today = new Date();
|
||||
const dayOfMonth = today.getDate();
|
||||
// @Cron('0 0 3 * * 1', {timeZone:'America/Toronto'}) // chaque premier lundi du mois à 03h00
|
||||
// async handleMonthlyArchival() {
|
||||
// const today = new Date();
|
||||
// const dayOfMonth = today.getDate();
|
||||
|
||||
if (dayOfMonth > 7) {
|
||||
this.logger.warn('Archive {awaiting 1st monday of the month for archivation process}')
|
||||
return;
|
||||
}
|
||||
// if (dayOfMonth > 7) {
|
||||
// this.logger.warn('Archive {awaiting 1st monday of the month for archivation process}')
|
||||
// return;
|
||||
// }
|
||||
|
||||
this.logger.log('monthly archivation in process');
|
||||
try {
|
||||
await this.timesheetsService.archiveOld();
|
||||
await this.expensesService.archiveOld();
|
||||
await this.shiftsService.archiveOld();
|
||||
// await this.leaveRequestsService.archiveExpired();
|
||||
this.logger.log('archivation process done');
|
||||
} catch (err) {
|
||||
this.logger.error('an error occured during archivation process ', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// this.logger.log('monthly archivation in process');
|
||||
// try {
|
||||
// await this.timesheetsService.archiveOld();
|
||||
// await this.expensesService.archiveOld();
|
||||
// await this.shiftsService.archiveOld();
|
||||
// // await this.leaveRequestsService.archiveExpired();
|
||||
// this.logger.log('archivation process done');
|
||||
// } catch (err) {
|
||||
// this.logger.error('an error occured during archivation process ', err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
@ -4,9 +4,7 @@ import {
|
|||
Controller,NotFoundException, UseInterceptors, Post, Get, Param, Res,
|
||||
UploadedFile, BadRequestException, UnsupportedMediaTypeException, Body, Delete,
|
||||
Query,
|
||||
DefaultValuePipe,
|
||||
ParseIntPipe
|
||||
} from "@nestjs/common";
|
||||
} from "@nestjs/common";
|
||||
import { maxUploadBytes, allowedMimes } from "../config/upload.config";
|
||||
import { memoryStorage } from 'multer';
|
||||
import { fileTypeFromBuffer, fileTypeFromFile } from "file-type";
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { Module } from "@nestjs/common";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { BankCodesControllers } from "./controllers/bank-codes.controller";
|
||||
import { BankCodesService } from "./services/bank-codes.service";
|
||||
// import { Module } from "@nestjs/common";
|
||||
// import { PrismaService } from "src/prisma/prisma.service";
|
||||
// import { BankCodesControllers } from "./controllers/bank-codes.controller";
|
||||
// import { BankCodesService } from "./services/bank-codes.service";
|
||||
|
||||
@Module({
|
||||
controllers: [BankCodesControllers],
|
||||
providers: [BankCodesService, PrismaService],
|
||||
})
|
||||
// @Module({
|
||||
// controllers: [BankCodesControllers],
|
||||
// providers: [BankCodesService, PrismaService],
|
||||
// })
|
||||
|
||||
export class BankCodesModule {}
|
||||
// export class BankCodesModule {}
|
||||
|
|
@ -1,49 +1,49 @@
|
|||
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from "@nestjs/common";
|
||||
import { BankCodesService } from "../services/bank-codes.service";
|
||||
import { CreateBankCodeDto } from "../dtos/create-bank-code.dto";
|
||||
import { UpdateBankCodeDto } from "../dtos/update-bank-code.dto";
|
||||
import { ApiBadRequestResponse, ApiNotFoundResponse, ApiOperation, ApiResponse } from "@nestjs/swagger";
|
||||
// import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from "@nestjs/common";
|
||||
// import { BankCodesService } from "../services/bank-codes.service";
|
||||
// import { CreateBankCodeDto } from "../dtos/create-bank-code.dto";
|
||||
// import { UpdateBankCodeDto } from "../dtos/update-bank-code.dto";
|
||||
// import { ApiBadRequestResponse, ApiNotFoundResponse, ApiOperation, ApiResponse } from "@nestjs/swagger";
|
||||
|
||||
@Controller('bank-codes')
|
||||
export class BankCodesControllers {
|
||||
constructor(private readonly bankCodesService: BankCodesService) {}
|
||||
//_____________________________________________________________________________________________
|
||||
// Deprecated or unused methods
|
||||
//_____________________________________________________________________________________________
|
||||
// @Controller('bank-codes')
|
||||
// export class BankCodesControllers {
|
||||
// constructor(private readonly bankCodesService: BankCodesService) {}
|
||||
// //_____________________________________________________________________________________________
|
||||
// // Deprecated or unused methods
|
||||
// //_____________________________________________________________________________________________
|
||||
|
||||
// @Post()
|
||||
// @ApiOperation({ summary: 'Create a new bank code' })
|
||||
// @ApiResponse({ status: 201, description: 'Bank code successfully created.' })
|
||||
// @ApiBadRequestResponse({ description: 'Invalid input data.' })
|
||||
// create(@Body() dto: CreateBankCodeDto) {
|
||||
// return this.bankCodesService.create(dto);
|
||||
// }
|
||||
// // @Post()
|
||||
// // @ApiOperation({ summary: 'Create a new bank code' })
|
||||
// // @ApiResponse({ status: 201, description: 'Bank code successfully created.' })
|
||||
// // @ApiBadRequestResponse({ description: 'Invalid input data.' })
|
||||
// // create(@Body() dto: CreateBankCodeDto) {
|
||||
// // return this.bankCodesService.create(dto);
|
||||
// // }
|
||||
|
||||
// @Get()
|
||||
// @ApiOperation({ summary: 'Retrieve all bank codes' })
|
||||
// @ApiResponse({ status: 200, description: 'List of bank codes.' })
|
||||
// findAll() {
|
||||
// return this.bankCodesService.findAll();
|
||||
// }
|
||||
// // @Get()
|
||||
// // @ApiOperation({ summary: 'Retrieve all bank codes' })
|
||||
// // @ApiResponse({ status: 200, description: 'List of bank codes.' })
|
||||
// // findAll() {
|
||||
// // return this.bankCodesService.findAll();
|
||||
// // }
|
||||
|
||||
// @Get(':id')
|
||||
// @ApiOperation({ summary: 'Retrieve a bank code by its ID' })
|
||||
// @ApiNotFoundResponse({ description: 'Bank code not found.' })
|
||||
// findOne(@Param('id', ParseIntPipe) id: number){
|
||||
// return this.bankCodesService.findOne(id);
|
||||
// }
|
||||
// // @Get(':id')
|
||||
// // @ApiOperation({ summary: 'Retrieve a bank code by its ID' })
|
||||
// // @ApiNotFoundResponse({ description: 'Bank code not found.' })
|
||||
// // findOne(@Param('id', ParseIntPipe) id: number){
|
||||
// // return this.bankCodesService.findOne(id);
|
||||
// // }
|
||||
|
||||
// @Patch(':id')
|
||||
// @ApiOperation({ summary: 'Update an existing bank code' })
|
||||
// @ApiNotFoundResponse({ description: 'Bank code not found.' })
|
||||
// update(@Param('id', ParseIntPipe) id: number, @Body() dto: UpdateBankCodeDto) {
|
||||
// return this.bankCodesService.update(id, dto)
|
||||
// }
|
||||
// // @Patch(':id')
|
||||
// // @ApiOperation({ summary: 'Update an existing bank code' })
|
||||
// // @ApiNotFoundResponse({ description: 'Bank code not found.' })
|
||||
// // update(@Param('id', ParseIntPipe) id: number, @Body() dto: UpdateBankCodeDto) {
|
||||
// // return this.bankCodesService.update(id, dto)
|
||||
// // }
|
||||
|
||||
// @Delete(':id')
|
||||
// @ApiOperation({ summary: 'Delete a bank code' })
|
||||
// @ApiNotFoundResponse({ description: 'Bank code not found.' })
|
||||
// remove(@Param('id', ParseIntPipe) id: number) {
|
||||
// return this.bankCodesService.remove(id);
|
||||
// }
|
||||
}
|
||||
// // @Delete(':id')
|
||||
// // @ApiOperation({ summary: 'Delete a bank code' })
|
||||
// // @ApiNotFoundResponse({ description: 'Bank code not found.' })
|
||||
// // remove(@Param('id', ParseIntPipe) id: number) {
|
||||
// // return this.bankCodesService.remove(id);
|
||||
// // }
|
||||
// }
|
||||
|
|
@ -1,46 +1,46 @@
|
|||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import { Allow, IsNotEmpty, IsNumber, IsString } from "class-validator";
|
||||
// import { ApiProperty } from "@nestjs/swagger";
|
||||
// import { Type } from "class-transformer";
|
||||
// import { Allow, IsNotEmpty, IsNumber, IsString } from "class-validator";
|
||||
|
||||
export class CreateBankCodeDto {
|
||||
@ApiProperty({
|
||||
example: 1,
|
||||
description: 'Unique ID of a bank-code (auto-generated)',
|
||||
readOnly: true,
|
||||
})
|
||||
@Allow()
|
||||
id: number;
|
||||
// export class CreateBankCodeDto {
|
||||
// @ApiProperty({
|
||||
// example: 1,
|
||||
// description: 'Unique ID of a bank-code (auto-generated)',
|
||||
// readOnly: true,
|
||||
// })
|
||||
// @Allow()
|
||||
// id: number;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'regular, vacation, emergency, sick, parental, etc',
|
||||
description: 'Type of codes',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
type: string;
|
||||
// @ApiProperty({
|
||||
// example: 'regular, vacation, emergency, sick, parental, etc',
|
||||
// description: 'Type of codes',
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsNotEmpty()
|
||||
// type: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'shift, expense, leave',
|
||||
description: 'categorie of the related code',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
categorie: string;
|
||||
// @ApiProperty({
|
||||
// example: 'shift, expense, leave',
|
||||
// description: 'categorie of the related code',
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsNotEmpty()
|
||||
// categorie: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: '0, 0.72, 1, 1.5, 2',
|
||||
description: 'modifier number to apply to salary',
|
||||
})
|
||||
@Type(()=> Number)
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
modifier: number;
|
||||
// @ApiProperty({
|
||||
// example: '0, 0.72, 1, 1.5, 2',
|
||||
// description: 'modifier number to apply to salary',
|
||||
// })
|
||||
// @Type(()=> Number)
|
||||
// @IsNumber()
|
||||
// @IsNotEmpty()
|
||||
// modifier: number;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'G1, G345, G501, G43, G700',
|
||||
description: 'codes given by the bank',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
bank_code: string;
|
||||
}
|
||||
// @ApiProperty({
|
||||
// example: 'G1, G345, G501, G43, G700',
|
||||
// description: 'codes given by the bank',
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsNotEmpty()
|
||||
// bank_code: string;
|
||||
// }
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { PartialType } from "@nestjs/swagger";
|
||||
import { CreateBankCodeDto } from "./create-bank-code.dto";
|
||||
// import { PartialType } from "@nestjs/swagger";
|
||||
// import { CreateBankCodeDto } from "./create-bank-code.dto";
|
||||
|
||||
export class UpdateBankCodeDto extends PartialType(CreateBankCodeDto) {}
|
||||
// export class UpdateBankCodeDto extends PartialType(CreateBankCodeDto) {}
|
||||
|
|
@ -1,51 +1,51 @@
|
|||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
import { CreateBankCodeDto } from "../dtos/create-bank-code.dto";
|
||||
import { BankCodes } from "@prisma/client";
|
||||
import { UpdateBankCodeDto } from "../dtos/update-bank-code.dto";
|
||||
// import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
// import { PrismaService } from "src/prisma/prisma.service";
|
||||
// import { CreateBankCodeDto } from "../dtos/create-bank-code.dto";
|
||||
// import { BankCodes } from "@prisma/client";
|
||||
// import { UpdateBankCodeDto } from "../dtos/update-bank-code.dto";
|
||||
|
||||
@Injectable()
|
||||
export class BankCodesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
// @Injectable()
|
||||
// export class BankCodesService {
|
||||
// constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async create(dto: CreateBankCodeDto): Promise<BankCodes>{
|
||||
return this.prisma.bankCodes.create({
|
||||
data: {
|
||||
type: dto.type,
|
||||
categorie: dto.categorie,
|
||||
modifier: dto.modifier,
|
||||
bank_code: dto.bank_code,
|
||||
},
|
||||
});
|
||||
}
|
||||
// async create(dto: CreateBankCodeDto): Promise<BankCodes>{
|
||||
// return this.prisma.bankCodes.create({
|
||||
// data: {
|
||||
// type: dto.type,
|
||||
// categorie: dto.categorie,
|
||||
// modifier: dto.modifier,
|
||||
// bank_code: dto.bank_code,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
findAll() {
|
||||
return this.prisma.bankCodes.findMany();
|
||||
}
|
||||
// findAll() {
|
||||
// return this.prisma.bankCodes.findMany();
|
||||
// }
|
||||
|
||||
async findOne(id: number) {
|
||||
const bankCode = await this.prisma.bankCodes.findUnique({ where: {id} });
|
||||
// async findOne(id: number) {
|
||||
// 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) {
|
||||
return await this.prisma.bankCodes.update({
|
||||
where: { id },
|
||||
data: {
|
||||
type: dto.type,
|
||||
categorie: dto.categorie,
|
||||
modifier: dto.modifier as any,
|
||||
bank_code: dto.bank_code,
|
||||
},
|
||||
});
|
||||
}
|
||||
// async update(id:number, dto: UpdateBankCodeDto) {
|
||||
// return await this.prisma.bankCodes.update({
|
||||
// where: { id },
|
||||
// data: {
|
||||
// type: dto.type,
|
||||
// categorie: dto.categorie,
|
||||
// modifier: dto.modifier as any,
|
||||
// bank_code: dto.bank_code,
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
async remove(id: number) {
|
||||
await this.findOne(id);
|
||||
return this.prisma.bankCodes.delete({ where: {id} });
|
||||
}
|
||||
// async remove(id: number) {
|
||||
// await this.findOne(id);
|
||||
// return this.prisma.bankCodes.delete({ where: {id} });
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
|
@ -1,79 +1,79 @@
|
|||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import {
|
||||
Allow,
|
||||
IsEmail,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsPositive,
|
||||
IsString,
|
||||
IsUUID,
|
||||
} from "class-validator";
|
||||
// import { ApiProperty } from "@nestjs/swagger";
|
||||
// import { Type } from "class-transformer";
|
||||
// import {
|
||||
// Allow,
|
||||
// IsEmail,
|
||||
// IsInt,
|
||||
// IsNotEmpty,
|
||||
// IsOptional,
|
||||
// IsPositive,
|
||||
// IsString,
|
||||
// IsUUID,
|
||||
// } from "class-validator";
|
||||
|
||||
export class CreateCustomerDto {
|
||||
@ApiProperty({
|
||||
example: 1,
|
||||
description: 'Unique ID of a customer(primary-key, auto-incremented)',
|
||||
})
|
||||
@Allow()
|
||||
id?: number;
|
||||
// export class CreateCustomerDto {
|
||||
// @ApiProperty({
|
||||
// example: 1,
|
||||
// description: 'Unique ID of a customer(primary-key, auto-incremented)',
|
||||
// })
|
||||
// @Allow()
|
||||
// id?: number;
|
||||
|
||||
@ApiProperty({
|
||||
example: '0e6e2e1f-b157-4c7c-ae3f-999b3e4f914d',
|
||||
description: 'UUID of the user linked to that customer',
|
||||
})
|
||||
@IsUUID()
|
||||
@IsOptional()
|
||||
user_id?: string;
|
||||
// @ApiProperty({
|
||||
// example: '0e6e2e1f-b157-4c7c-ae3f-999b3e4f914d',
|
||||
// description: 'UUID of the user linked to that customer',
|
||||
// })
|
||||
// @IsUUID()
|
||||
// @IsOptional()
|
||||
// user_id?: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'Gandalf',
|
||||
description: 'Customer`s first name',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
first_name: string;
|
||||
// @ApiProperty({
|
||||
// example: 'Gandalf',
|
||||
// description: 'Customer`s first name',
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsNotEmpty()
|
||||
// first_name: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'TheGray',
|
||||
description: 'Customer`s last name',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
last_name: string;
|
||||
// @ApiProperty({
|
||||
// example: 'TheGray',
|
||||
// description: 'Customer`s last name',
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsNotEmpty()
|
||||
// last_name: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'you_shall_not_pass@middleEarth.com',
|
||||
description: 'Customer`s email',
|
||||
})
|
||||
@IsEmail()
|
||||
@IsOptional()
|
||||
email: string;
|
||||
// @ApiProperty({
|
||||
// example: 'you_shall_not_pass@middleEarth.com',
|
||||
// description: 'Customer`s email',
|
||||
// })
|
||||
// @IsEmail()
|
||||
// @IsOptional()
|
||||
// email: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: '8436637464',
|
||||
description: 'Customer`s phone number',
|
||||
})
|
||||
@IsString()
|
||||
phone_number: string;
|
||||
// @ApiProperty({
|
||||
// example: '8436637464',
|
||||
// description: 'Customer`s phone number',
|
||||
// })
|
||||
// @IsString()
|
||||
// phone_number: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: '1 Ringbearer`s way, Mount Doom city, ME, T1R 1N6 ',
|
||||
description: 'Customer`s residence',
|
||||
required: false,
|
||||
})
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
residence?: string;
|
||||
// @ApiProperty({
|
||||
// example: '1 Ringbearer`s way, Mount Doom city, ME, T1R 1N6 ',
|
||||
// description: 'Customer`s residence',
|
||||
// required: false,
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsOptional()
|
||||
// residence?: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: '4263253',
|
||||
description: 'Customer`s invoice number',
|
||||
required: false,
|
||||
})
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
invoice_id: number;
|
||||
}
|
||||
// @ApiProperty({
|
||||
// example: '4263253',
|
||||
// description: 'Customer`s invoice number',
|
||||
// required: false,
|
||||
// })
|
||||
// @Type(() => Number)
|
||||
// @IsInt()
|
||||
// @IsNotEmpty()
|
||||
// invoice_id: number;
|
||||
// }
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { PartialType } from "@nestjs/swagger";
|
||||
import { CreateCustomerDto } from "./create-customer.dto";
|
||||
// import { PartialType } from "@nestjs/swagger";
|
||||
// import { CreateCustomerDto } from "./create-customer.dto";
|
||||
|
||||
export class UpdateCustomerDto extends PartialType(CreateCustomerDto) {}
|
||||
// export class UpdateCustomerDto extends PartialType(CreateCustomerDto) {}
|
||||
|
|
@ -1,93 +1,93 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
// import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class CustomersService {
|
||||
// @Injectable()
|
||||
// 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> {
|
||||
// const {
|
||||
// first_name,
|
||||
// last_name,
|
||||
// email,
|
||||
// phone_number,
|
||||
// residence,
|
||||
// invoice_id,
|
||||
// } = dto;
|
||||
// // async create(dto: CreateCustomerDto): Promise<Customers> {
|
||||
// // const {
|
||||
// // first_name,
|
||||
// // last_name,
|
||||
// // email,
|
||||
// // phone_number,
|
||||
// // residence,
|
||||
// // invoice_id,
|
||||
// // } = 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.customers.create({
|
||||
// data: {
|
||||
// user_id: user.id,
|
||||
// invoice_id,
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// // return this.prisma.$transaction(async (transaction) => {
|
||||
// // const user: Users = await transaction.users.create({
|
||||
// // data: {
|
||||
// // first_name,
|
||||
// // last_name,
|
||||
// // email,
|
||||
// // phone_number,
|
||||
// // residence,
|
||||
// // },
|
||||
// // });
|
||||
// // return transaction.customers.create({
|
||||
// // data: {
|
||||
// // user_id: user.id,
|
||||
// // invoice_id,
|
||||
// // },
|
||||
// // });
|
||||
// // });
|
||||
// // }
|
||||
|
||||
// findAll(): Promise<Customers[]> {
|
||||
// return this.prisma.customers.findMany({
|
||||
// include: { user: true },
|
||||
// })
|
||||
// }
|
||||
// // findAll(): Promise<Customers[]> {
|
||||
// // return this.prisma.customers.findMany({
|
||||
// // include: { user: true },
|
||||
// // })
|
||||
// // }
|
||||
|
||||
// async findOne(id:number): Promise<Customers> {
|
||||
// const customer = await this.prisma.customers.findUnique({
|
||||
// where: { id },
|
||||
// include: { user: true },
|
||||
// });
|
||||
// if(!customer) throw new NotFoundException(`Customer #${id} not found`);
|
||||
// return customer;
|
||||
// }
|
||||
// // async findOne(id:number): Promise<Customers> {
|
||||
// // const customer = await this.prisma.customers.findUnique({
|
||||
// // where: { id },
|
||||
// // include: { user: true },
|
||||
// // });
|
||||
// // if(!customer) throw new NotFoundException(`Customer #${id} not found`);
|
||||
// // return customer;
|
||||
// // }
|
||||
|
||||
// async update(id: number,dto: UpdateCustomerDto): Promise<Customers> {
|
||||
// const customer = await this.findOne(id);
|
||||
// // async update(id: number,dto: UpdateCustomerDto): Promise<Customers> {
|
||||
// // const customer = await this.findOne(id);
|
||||
|
||||
// const {
|
||||
// first_name,
|
||||
// last_name,
|
||||
// email,
|
||||
// phone_number,
|
||||
// residence,
|
||||
// invoice_id,
|
||||
// } = dto;
|
||||
// // const {
|
||||
// // first_name,
|
||||
// // last_name,
|
||||
// // email,
|
||||
// // phone_number,
|
||||
// // residence,
|
||||
// // invoice_id,
|
||||
// // } = dto;
|
||||
|
||||
// return this.prisma.$transaction(async (transaction) => {
|
||||
// await transaction.users.update({
|
||||
// where: { id: customer.user_id },
|
||||
// data: {
|
||||
// ...(first_name !== undefined && { first_name }),
|
||||
// ...(last_name !== undefined && { last_name }),
|
||||
// ...(email !== undefined && { email }),
|
||||
// ...(phone_number !== undefined && { phone_number }),
|
||||
// ...(residence !== undefined && { residence }),
|
||||
// },
|
||||
// });
|
||||
// // return this.prisma.$transaction(async (transaction) => {
|
||||
// // await transaction.users.update({
|
||||
// // where: { id: customer.user_id },
|
||||
// // data: {
|
||||
// // ...(first_name !== undefined && { first_name }),
|
||||
// // ...(last_name !== undefined && { last_name }),
|
||||
// // ...(email !== undefined && { email }),
|
||||
// // ...(phone_number !== undefined && { phone_number }),
|
||||
// // ...(residence !== undefined && { residence }),
|
||||
// // },
|
||||
// // });
|
||||
|
||||
// return transaction.customers.update({
|
||||
// where: { id },
|
||||
// data: {
|
||||
// ...(invoice_id !== undefined && { invoice_id }),
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
// // return transaction.customers.update({
|
||||
// // where: { id },
|
||||
// // data: {
|
||||
// // ...(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 }});
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,118 +1,118 @@
|
|||
import {
|
||||
Allow,
|
||||
IsBoolean,
|
||||
IsDateString,
|
||||
IsEmail,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsPositive,
|
||||
IsString,
|
||||
IsUUID,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
// import {
|
||||
// Allow,
|
||||
// IsBoolean,
|
||||
// IsDateString,
|
||||
// IsEmail,
|
||||
// IsInt,
|
||||
// IsNotEmpty,
|
||||
// IsOptional,
|
||||
// IsPositive,
|
||||
// IsString,
|
||||
// IsUUID,
|
||||
// } from 'class-validator';
|
||||
// import { Type } from 'class-transformer';
|
||||
// import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class CreateEmployeeDto {
|
||||
@ApiProperty({
|
||||
example: 1,
|
||||
description: 'Unique ID of an employee(primary-key, auto-incremented)',
|
||||
})
|
||||
@Allow()
|
||||
id: number;
|
||||
// export class CreateEmployeeDto {
|
||||
// @ApiProperty({
|
||||
// example: 1,
|
||||
// description: 'Unique ID of an employee(primary-key, auto-incremented)',
|
||||
// })
|
||||
// @Allow()
|
||||
// id: number;
|
||||
|
||||
@ApiProperty({
|
||||
example: '0e6e2e1f-b157-4c7c-ae3f-999b3e4f914d',
|
||||
description: 'UUID of the user linked to that employee',
|
||||
})
|
||||
@IsUUID()
|
||||
@IsOptional()
|
||||
user_id?: string;
|
||||
// @ApiProperty({
|
||||
// example: '0e6e2e1f-b157-4c7c-ae3f-999b3e4f914d',
|
||||
// description: 'UUID of the user linked to that employee',
|
||||
// })
|
||||
// @IsUUID()
|
||||
// @IsOptional()
|
||||
// user_id?: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'Frodo',
|
||||
description: 'Employee`s first name',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
first_name: string;
|
||||
// @ApiProperty({
|
||||
// example: 'Frodo',
|
||||
// description: 'Employee`s first name',
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsNotEmpty()
|
||||
// first_name: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'Baggins',
|
||||
description: 'Employee`s last name',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
last_name: string;
|
||||
// @ApiProperty({
|
||||
// example: 'Baggins',
|
||||
// description: 'Employee`s last name',
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsNotEmpty()
|
||||
// last_name: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 'i_cant_do_this_sam@targointernet.com',
|
||||
description: 'Employee`s email',
|
||||
})
|
||||
@IsEmail()
|
||||
@IsOptional()
|
||||
email: string;
|
||||
// @ApiProperty({
|
||||
// example: 'i_cant_do_this_sam@targointernet.com',
|
||||
// description: 'Employee`s email',
|
||||
// })
|
||||
// @IsEmail()
|
||||
// @IsOptional()
|
||||
// email: string;
|
||||
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
is_supervisor: boolean;
|
||||
// @IsOptional()
|
||||
// @IsBoolean()
|
||||
// is_supervisor: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
example: '82538437464',
|
||||
description: 'Employee`s phone number',
|
||||
})
|
||||
@IsString()
|
||||
phone_number: string;
|
||||
// @ApiProperty({
|
||||
// example: '82538437464',
|
||||
// description: 'Employee`s phone number',
|
||||
// })
|
||||
// @IsString()
|
||||
// phone_number: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: '1 Bagshot Row, Hobbiton, The Shire, Middle-earth',
|
||||
description: 'Employee`s residence',
|
||||
required: false,
|
||||
})
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
residence?: string;
|
||||
// @ApiProperty({
|
||||
// example: '1 Bagshot Row, Hobbiton, The Shire, Middle-earth',
|
||||
// description: 'Employee`s residence',
|
||||
// required: false,
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsOptional()
|
||||
// residence?: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: 7464,
|
||||
description: 'external ID for the pay system',
|
||||
})
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
@Type(() => Number)
|
||||
external_payroll_id: number;
|
||||
// @ApiProperty({
|
||||
// example: 7464,
|
||||
// description: 'external ID for the pay system',
|
||||
// })
|
||||
// @IsInt()
|
||||
// @IsPositive()
|
||||
// @Type(() => Number)
|
||||
// external_payroll_id: number;
|
||||
|
||||
@ApiProperty({
|
||||
example: 335567447,
|
||||
description: 'Employee`s company code',
|
||||
})
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
@Type(() => Number)
|
||||
company_code: number;
|
||||
// @ApiProperty({
|
||||
// example: 335567447,
|
||||
// description: 'Employee`s company code',
|
||||
// })
|
||||
// @IsInt()
|
||||
// @IsPositive()
|
||||
// @Type(() => Number)
|
||||
// company_code: number;
|
||||
|
||||
@ApiProperty({
|
||||
example:'technicient',
|
||||
description: 'employee`s job title',
|
||||
})
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
job_title: string;
|
||||
// @ApiProperty({
|
||||
// example:'technicient',
|
||||
// description: 'employee`s job title',
|
||||
// })
|
||||
// @IsString()
|
||||
// @IsOptional()
|
||||
// job_title: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: '23/09/3018',
|
||||
description: 'Employee`s first working day',
|
||||
})
|
||||
@IsDateString()
|
||||
first_work_day: string;
|
||||
// @ApiProperty({
|
||||
// example: '23/09/3018',
|
||||
// description: 'Employee`s first working day',
|
||||
// })
|
||||
// @IsDateString()
|
||||
// first_work_day: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: '25/03/3019',
|
||||
description: 'Employee`s last working day',
|
||||
required: false,
|
||||
})
|
||||
@IsDateString()
|
||||
@IsOptional()
|
||||
last_work_day?: string;
|
||||
}
|
||||
// @ApiProperty({
|
||||
// example: '25/03/3019',
|
||||
// description: 'Employee`s last working day',
|
||||
// required: false,
|
||||
// })
|
||||
// @IsDateString()
|
||||
// @IsOptional()
|
||||
// last_work_day?: string;
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
export class EmployeeListItemDto {
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
email: string;
|
||||
supervisor_full_name: string | null;
|
||||
company_name: number | null;
|
||||
job_title: string | null;
|
||||
}
|
||||
// export class EmployeeListItemDto {
|
||||
// first_name: string;
|
||||
// last_name: string;
|
||||
// email: string;
|
||||
// supervisor_full_name: string | null;
|
||||
// company_name: number | null;
|
||||
// job_title: string | null;
|
||||
// }
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
export class EmployeeProfileItemDto {
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
employee_full_name: string;
|
||||
supervisor_full_name: string | null;
|
||||
company_name: number | null;
|
||||
job_title: string | null;
|
||||
email: string | null;
|
||||
phone_number: string;
|
||||
first_work_day: string;
|
||||
last_work_day?: string | null;
|
||||
residence: string | null;
|
||||
}
|
||||
// export class EmployeeProfileItemDto {
|
||||
// first_name: string;
|
||||
// last_name: string;
|
||||
// employee_full_name: string;
|
||||
// supervisor_full_name: string | null;
|
||||
// company_name: number | null;
|
||||
// job_title: string | null;
|
||||
// email: string | null;
|
||||
// phone_number: string;
|
||||
// first_work_day: string;
|
||||
// last_work_day?: string | null;
|
||||
// residence: string | null;
|
||||
// }
|
||||
|
|
@ -1,22 +1,22 @@
|
|||
import { ApiProperty, PartialType } from '@nestjs/swagger';
|
||||
import { CreateEmployeeDto } from './create-employee.dto';
|
||||
import { IsDateString, IsOptional, Max } from 'class-validator';
|
||||
// import { ApiProperty, PartialType } from '@nestjs/swagger';
|
||||
// import { CreateEmployeeDto } from './create-employee.dto';
|
||||
// import { IsDateString, IsOptional, Max } from 'class-validator';
|
||||
|
||||
export class UpdateEmployeeDto extends PartialType(CreateEmployeeDto) {
|
||||
@ApiProperty({ required: false, type: Date, description: 'New hire date or undefined' })
|
||||
@IsDateString()
|
||||
@IsOptional()
|
||||
first_work_day?: string;
|
||||
// export class UpdateEmployeeDto extends PartialType(CreateEmployeeDto) {
|
||||
// @ApiProperty({ required: false, type: Date, description: 'New hire date or undefined' })
|
||||
// @IsDateString()
|
||||
// @IsOptional()
|
||||
// first_work_day?: string;
|
||||
|
||||
@ApiProperty({ required: false, type: Date, description: 'Termination date (null to restore)' })
|
||||
@IsDateString()
|
||||
@IsOptional()
|
||||
last_work_day?: string;
|
||||
// @ApiProperty({ required: false, type: Date, description: 'Termination date (null to restore)' })
|
||||
// @IsDateString()
|
||||
// @IsOptional()
|
||||
// last_work_day?: string;
|
||||
|
||||
@ApiProperty({ required: false, type: Number, description: 'Supervisor ID' })
|
||||
@IsOptional()
|
||||
supervisor_id?: number;
|
||||
// @ApiProperty({ required: false, type: Number, description: 'Supervisor ID' })
|
||||
// @IsOptional()
|
||||
// supervisor_id?: number;
|
||||
|
||||
@IsOptional()
|
||||
phone_number: string;
|
||||
}
|
||||
// @IsOptional()
|
||||
// phone_number: string;
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -1,230 +1,230 @@
|
|||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from 'src/prisma/prisma.service';
|
||||
import { EmployeeListItemDto } from '../dtos/list-employee.dto';
|
||||
import { EmployeeProfileItemDto } from '../dtos/profil-employee.dto';
|
||||
// import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
// import { PrismaService } from 'src/prisma/prisma.service';
|
||||
// import { EmployeeListItemDto } from '../dtos/list-employee.dto';
|
||||
// import { EmployeeProfileItemDto } from '../dtos/profil-employee.dto';
|
||||
|
||||
@Injectable()
|
||||
export class EmployeesService {
|
||||
constructor(private readonly prisma: PrismaService) { }
|
||||
// @Injectable()
|
||||
// export class EmployeesService {
|
||||
// constructor(private readonly prisma: PrismaService) { }
|
||||
|
||||
findListEmployees(): Promise<EmployeeListItemDto[]> {
|
||||
return this.prisma.employees.findMany({
|
||||
select: {
|
||||
user: {
|
||||
select: {
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
supervisor: {
|
||||
select: {
|
||||
user: {
|
||||
select: {
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
job_title: true,
|
||||
company_code: true,
|
||||
}
|
||||
}).then(rows => rows.map(r => ({
|
||||
first_name: r.user.first_name,
|
||||
last_name: r.user.last_name,
|
||||
email: r.user.email,
|
||||
company_name: r.company_code,
|
||||
job_title: r.job_title,
|
||||
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,
|
||||
})),
|
||||
);
|
||||
}
|
||||
// findListEmployees(): Promise<EmployeeListItemDto[]> {
|
||||
// return this.prisma.employees.findMany({
|
||||
// select: {
|
||||
// user: {
|
||||
// select: {
|
||||
// first_name: true,
|
||||
// last_name: true,
|
||||
// email: true,
|
||||
// },
|
||||
// },
|
||||
// supervisor: {
|
||||
// select: {
|
||||
// user: {
|
||||
// select: {
|
||||
// first_name: true,
|
||||
// last_name: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// job_title: true,
|
||||
// company_code: true,
|
||||
// }
|
||||
// }).then(rows => rows.map(r => ({
|
||||
// first_name: r.user.first_name,
|
||||
// last_name: r.user.last_name,
|
||||
// email: r.user.email,
|
||||
// company_name: r.company_code,
|
||||
// job_title: r.job_title,
|
||||
// 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,
|
||||
// })),
|
||||
// );
|
||||
// }
|
||||
|
||||
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`);
|
||||
// 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,
|
||||
company_name: emp.company_code,
|
||||
job_title: emp.job_title,
|
||||
employee_full_name: `${emp.user.first_name} ${emp.user.last_name}`,
|
||||
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,
|
||||
supervisor_full_name: emp.supervisor ? `${emp.supervisor.user.first_name}, ${emp.supervisor.user.last_name}` : null,
|
||||
};
|
||||
}
|
||||
// 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,
|
||||
// company_name: emp.company_code,
|
||||
// job_title: emp.job_title,
|
||||
// employee_full_name: `${emp.user.first_name} ${emp.user.last_name}`,
|
||||
// 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,
|
||||
// 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> {
|
||||
// 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;
|
||||
// // 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,
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// // 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[]> {
|
||||
// return this.prisma.employees.findMany({
|
||||
// include: { user: true },
|
||||
// });
|
||||
// }
|
||||
// // findAll(): Promise<Employees[]> {
|
||||
// // return this.prisma.employees.findMany({
|
||||
// // include: { user: true },
|
||||
// // });
|
||||
// // }
|
||||
|
||||
// async findOne(email: string): Promise<Employees> {
|
||||
// const emp = await this.prisma.employees.findFirst({
|
||||
// where: { user: { email } },
|
||||
// include: { user: true },
|
||||
// });
|
||||
// // async findOne(email: string): Promise<Employees> {
|
||||
// // const emp = await this.prisma.employees.findFirst({
|
||||
// // where: { user: { email } },
|
||||
// // include: { user: true },
|
||||
// // });
|
||||
|
||||
// //add search for archived employees
|
||||
// if (!emp) {
|
||||
// throw new NotFoundException(`Employee with email: ${email} not found`);
|
||||
// }
|
||||
// return emp;
|
||||
// }
|
||||
// // //add search for archived employees
|
||||
// // if (!emp) {
|
||||
// // throw new NotFoundException(`Employee with email: ${email} not found`);
|
||||
// // }
|
||||
// // return emp;
|
||||
// // }
|
||||
|
||||
// async update(
|
||||
// email: string,
|
||||
// dto: UpdateEmployeeDto,
|
||||
// ): Promise<Employees> {
|
||||
// const emp = await this.findOne(email);
|
||||
// // async update(
|
||||
// // email: string,
|
||||
// // dto: UpdateEmployeeDto,
|
||||
// // ): Promise<Employees> {
|
||||
// // const emp = await this.findOne(email);
|
||||
|
||||
// const {
|
||||
// first_name,
|
||||
// last_name,
|
||||
// phone_number,
|
||||
// residence,
|
||||
// external_payroll_id,
|
||||
// company_code,
|
||||
// job_title,
|
||||
// first_work_day,
|
||||
// last_work_day,
|
||||
// is_supervisor,
|
||||
// email: new_email,
|
||||
// } = dto;
|
||||
// // const {
|
||||
// // first_name,
|
||||
// // last_name,
|
||||
// // phone_number,
|
||||
// // residence,
|
||||
// // external_payroll_id,
|
||||
// // company_code,
|
||||
// // job_title,
|
||||
// // first_work_day,
|
||||
// // last_work_day,
|
||||
// // is_supervisor,
|
||||
// // email: new_email,
|
||||
// // } = dto;
|
||||
|
||||
// return this.prisma.$transaction(async (transaction) => {
|
||||
// if(
|
||||
// first_name !== undefined ||
|
||||
// last_name !== undefined ||
|
||||
// new_email !== undefined ||
|
||||
// phone_number !== undefined ||
|
||||
// residence !== undefined
|
||||
// ){
|
||||
// await transaction.users.update({
|
||||
// where: { id: emp.user_id },
|
||||
// data: {
|
||||
// ...(first_name !== undefined && { first_name }),
|
||||
// ...(last_name !== undefined && { last_name }),
|
||||
// ...(email !== undefined && { email }),
|
||||
// ...(phone_number !== undefined && { phone_number }),
|
||||
// ...(residence !== undefined && { residence }),
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// // return this.prisma.$transaction(async (transaction) => {
|
||||
// // if(
|
||||
// // first_name !== undefined ||
|
||||
// // last_name !== undefined ||
|
||||
// // new_email !== undefined ||
|
||||
// // phone_number !== undefined ||
|
||||
// // residence !== undefined
|
||||
// // ){
|
||||
// // await transaction.users.update({
|
||||
// // where: { id: emp.user_id },
|
||||
// // data: {
|
||||
// // ...(first_name !== undefined && { first_name }),
|
||||
// // ...(last_name !== undefined && { last_name }),
|
||||
// // ...(email !== undefined && { email }),
|
||||
// // ...(phone_number !== undefined && { phone_number }),
|
||||
// // ...(residence !== undefined && { residence }),
|
||||
// // },
|
||||
// // });
|
||||
// // }
|
||||
|
||||
// const updated = await transaction.employees.update({
|
||||
// where: { id: emp.id },
|
||||
// data: {
|
||||
// ...(external_payroll_id !== undefined && { external_payroll_id }),
|
||||
// ...(company_code !== undefined && { company_code }),
|
||||
// ...(first_work_day !== undefined && { first_work_day }),
|
||||
// ...(last_work_day !== undefined && { last_work_day }),
|
||||
// ...(job_title !== undefined && { job_title }),
|
||||
// ...(is_supervisor !== undefined && { is_supervisor }),
|
||||
// },
|
||||
// });
|
||||
// return updated;
|
||||
// });
|
||||
// }
|
||||
// // const updated = await transaction.employees.update({
|
||||
// // where: { id: emp.id },
|
||||
// // data: {
|
||||
// // ...(external_payroll_id !== undefined && { external_payroll_id }),
|
||||
// // ...(company_code !== undefined && { company_code }),
|
||||
// // ...(first_work_day !== undefined && { first_work_day }),
|
||||
// // ...(last_work_day !== undefined && { last_work_day }),
|
||||
// // ...(job_title !== undefined && { job_title }),
|
||||
// // ...(is_supervisor !== undefined && { is_supervisor }),
|
||||
// // },
|
||||
// // });
|
||||
// // 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) => {
|
||||
// await transaction.employees.updateMany({
|
||||
// where: { supervisor_id: emp.id },
|
||||
// data: { supervisor_id: null },
|
||||
// });
|
||||
// const deleted_employee = await transaction.employees.delete({
|
||||
// where: {id: emp.id },
|
||||
// });
|
||||
// await transaction.users.delete({
|
||||
// where: { id: emp.user_id },
|
||||
// });
|
||||
// return deleted_employee;
|
||||
// });
|
||||
// }
|
||||
// // return this.prisma.$transaction(async (transaction) => {
|
||||
// // await transaction.employees.updateMany({
|
||||
// // where: { supervisor_id: emp.id },
|
||||
// // data: { supervisor_id: null },
|
||||
// // });
|
||||
// // const deleted_employee = await transaction.employees.delete({
|
||||
// // where: {id: emp.id },
|
||||
// // });
|
||||
// // await transaction.users.delete({
|
||||
// // where: { id: emp.user_id },
|
||||
// // });
|
||||
// // return deleted_employee;
|
||||
// // });
|
||||
// // }
|
||||
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
export function toDateOrNull(v?: string | null): Date | null {
|
||||
if (!v) return null;
|
||||
const day = new Date(v);
|
||||
return isNaN(day.getTime()) ? null : day;
|
||||
}
|
||||
export function toDateOrUndefined(v?: string | null): Date | undefined {
|
||||
const day = toDateOrNull(v ?? undefined);
|
||||
return day === null ? undefined : day;
|
||||
}
|
||||
// export function toDateOrNull(v?: string | null): Date | null {
|
||||
// if (!v) return null;
|
||||
// const day = new Date(v);
|
||||
// return isNaN(day.getTime()) ? null : day;
|
||||
// }
|
||||
// export function toDateOrUndefined(v?: string | null): Date | undefined {
|
||||
// const day = toDateOrNull(v ?? undefined);
|
||||
// return day === null ? undefined : day;
|
||||
// }
|
||||
Loading…
Reference in New Issue
Block a user