From f874d2c5c64191f8083deece2ead644b0fcbd972 Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Wed, 30 Jul 2025 14:39:43 -0400 Subject: [PATCH] BREAKING CHANGE(bank_codes): shift-codes table and expenses-codes table deleted and refactoring of modules calling "x-codes" to use bank-codes --- .../migration.sql | 16 +++ prisma/schema.prisma | 26 ++--- src/modules/bank-codes/bank-codes.module.ts | 12 ++ .../controllers/bank-codes.controller.ts | 46 ++++++++ .../bank-codes/dtos/create-bank-codes.ts | 20 ++++ .../swagger-entities/bank_codes.entity.ts | 34 ++++++ .../bank-codes/dtos/update-bank-codes.ts | 4 + .../services/bank-codes.services.ts | 38 ++++++ .../controllers/expense-codes.controller.ts | 64 ---------- .../expense-codes/dtos/create-expense-code.ts | 21 ---- .../swagger-entities/expense-codes.entity.ts | 21 ---- .../expense-codes/dtos/update-expense-code.ts | 4 - .../expense-codes/expense-codes.module.ts | 11 -- .../services/expense-codes.service.ts | 99 ---------------- src/modules/expenses/dtos/create-expense.ts | 31 +---- .../dtos/swagger-entities/expenses.entity.ts | 4 +- .../expenses/services/expenses.service.ts | 16 +-- .../controllers/shift-codes.controller.ts | 64 ---------- .../dtos/create-shift-codes.dto.ts | 21 ---- .../swagger-entities/shift-codes.entity.ts | 21 ---- .../dtos/update-shift-codes.dto.ts | 4 - .../services/shift-codes.service.ts | 109 ------------------ src/modules/shift-codes/shift-codes.module.ts | 11 -- src/modules/shifts/dtos/create-shifts.dto.ts | 27 +---- .../dtos/swagger-entities/shift.entity.ts | 4 +- src/modules/shifts/services/shifts.service.ts | 16 +-- 26 files changed, 205 insertions(+), 539 deletions(-) create mode 100644 prisma/migrations/20250730183752_fix_bank_codes_relations/migration.sql create mode 100644 src/modules/bank-codes/bank-codes.module.ts create mode 100644 src/modules/bank-codes/controllers/bank-codes.controller.ts create mode 100644 src/modules/bank-codes/dtos/create-bank-codes.ts create mode 100644 src/modules/bank-codes/dtos/swagger-entities/bank_codes.entity.ts create mode 100644 src/modules/bank-codes/dtos/update-bank-codes.ts create mode 100644 src/modules/bank-codes/services/bank-codes.services.ts delete mode 100644 src/modules/expense-codes/controllers/expense-codes.controller.ts delete mode 100644 src/modules/expense-codes/dtos/create-expense-code.ts delete mode 100644 src/modules/expense-codes/dtos/swagger-entities/expense-codes.entity.ts delete mode 100644 src/modules/expense-codes/dtos/update-expense-code.ts delete mode 100644 src/modules/expense-codes/expense-codes.module.ts delete mode 100644 src/modules/expense-codes/services/expense-codes.service.ts delete mode 100644 src/modules/shift-codes/controllers/shift-codes.controller.ts delete mode 100644 src/modules/shift-codes/dtos/create-shift-codes.dto.ts delete mode 100644 src/modules/shift-codes/dtos/swagger-entities/shift-codes.entity.ts delete mode 100644 src/modules/shift-codes/dtos/update-shift-codes.dto.ts delete mode 100644 src/modules/shift-codes/services/shift-codes.service.ts delete mode 100644 src/modules/shift-codes/shift-codes.module.ts diff --git a/prisma/migrations/20250730183752_fix_bank_codes_relations/migration.sql b/prisma/migrations/20250730183752_fix_bank_codes_relations/migration.sql new file mode 100644 index 0000000..0ee1569 --- /dev/null +++ b/prisma/migrations/20250730183752_fix_bank_codes_relations/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - You are about to drop the column `expense_code_id` on the `expenses_archive` table. All the data in the column will be lost. + - You are about to drop the column `shift_code_id` on the `shifts_archive` table. All the data in the column will be lost. + - Added the required column `bank_code_id` to the `expenses_archive` table without a default value. This is not possible if the table is not empty. + - Added the required column `bank_code_id` to the `shifts_archive` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "expenses_archive" DROP COLUMN "expense_code_id", +ADD COLUMN "bank_code_id" INTEGER NOT NULL; + +-- AlterTable +ALTER TABLE "shifts_archive" DROP COLUMN "shift_code_id", +ADD COLUMN "bank_code_id" INTEGER NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index dabd4ce..edb3ca1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -132,7 +132,7 @@ model LeaveRequestsArchive { //pay-period vue view PayPeriods { - period_number Int @id + period_number Int @id //do not try to fix it, Prisma is working on a fix for views start_date DateTime @db.Date end_date DateTime @db.Date year Int @@ -169,7 +169,7 @@ model Shifts { id Int @id @default(autoincrement()) timesheet Timesheets @relation("ShiftTimesheet", fields: [timesheet_id], references: [id]) timesheet_id Int - shift_code BankCodes @relation("ShiftBankCodes", fields: [bank_code_id], references: [id]) + bank_code BankCodes @relation("ShiftBankCodes", fields: [bank_code_id], references: [id]) bank_code_id Int description String? date DateTime @db.Date @@ -182,16 +182,16 @@ model Shifts { } model ShiftsArchive { - id Int @id @default(autoincrement()) - shift Shifts @relation("ShiftsToArchive", fields: [shift_id], references: [id]) - shift_id Int - archive_at DateTime @default(now()) - timesheet_id Int - shift_code_id Int - description String? - date DateTime @db.Date - start_time DateTime @db.Time(0) - end_time DateTime @db.Time(0) + id Int @id @default(autoincrement()) + shift Shifts @relation("ShiftsToArchive", fields: [shift_id], references: [id]) + shift_id Int + archive_at DateTime @default(now()) + timesheet_id Int + bank_code_id Int + description String? + date DateTime @db.Date + start_time DateTime @db.Time(0) + end_time DateTime @db.Time(0) @@map("shifts_archive") } @@ -234,7 +234,7 @@ model ExpensesArchive { expense_id Int timesheet_id Int archived_at DateTime @default(now()) - expense_code_id Int + bank_code_id Int date DateTime @db.Date amount Decimal @db.Money attachement String? diff --git a/src/modules/bank-codes/bank-codes.module.ts b/src/modules/bank-codes/bank-codes.module.ts new file mode 100644 index 0000000..a8c4ced --- /dev/null +++ b/src/modules/bank-codes/bank-codes.module.ts @@ -0,0 +1,12 @@ +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.services"; + +@Module({ + controllers: [BankCodesControllers], + providers: [BankCodesService, PrismaService], +}) + +export class ShiftCodesModule {} \ No newline at end of file diff --git a/src/modules/bank-codes/controllers/bank-codes.controller.ts b/src/modules/bank-codes/controllers/bank-codes.controller.ts new file mode 100644 index 0000000..f8a44fa --- /dev/null +++ b/src/modules/bank-codes/controllers/bank-codes.controller.ts @@ -0,0 +1,46 @@ +import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from "@nestjs/common"; +import { BankCodesService } from "../services/bank-codes.services"; +import { CreateBankCodeDto } from "../dtos/create-bank-codes"; +import { UpdateBankCodeDto } from "../dtos/update-bank-codes"; +import { ApiBadRequestResponse, ApiNotFoundResponse, ApiOperation, ApiResponse } from "@nestjs/swagger"; + +@Controller('bank-codes') +export class BankCodesControllers { + constructor(private readonly bankCodesService: BankCodesService) {} + + @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(':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) + } + + @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); + } +} \ No newline at end of file diff --git a/src/modules/bank-codes/dtos/create-bank-codes.ts b/src/modules/bank-codes/dtos/create-bank-codes.ts new file mode 100644 index 0000000..fe3807d --- /dev/null +++ b/src/modules/bank-codes/dtos/create-bank-codes.ts @@ -0,0 +1,20 @@ +import { IsNotEmpty, IsNumber, IsString } from "class-validator"; + +export class CreateBankCodeDto { + + @IsString() + @IsNotEmpty() + type: string; + + @IsString() + @IsNotEmpty() + categorie: string; + + @IsNumber() + @IsNotEmpty() + modifier: number; + + @IsString() + @IsNotEmpty() + bank_code: string; +} \ No newline at end of file diff --git a/src/modules/bank-codes/dtos/swagger-entities/bank_codes.entity.ts b/src/modules/bank-codes/dtos/swagger-entities/bank_codes.entity.ts new file mode 100644 index 0000000..c3f6686 --- /dev/null +++ b/src/modules/bank-codes/dtos/swagger-entities/bank_codes.entity.ts @@ -0,0 +1,34 @@ +import { ApiProperty } from "@nestjs/swagger"; + +export class BankCodesEntity { + + @ApiProperty({ + example: 1, + description: 'Unique ID of a bank-code (auto-generated)', + }) + id: number; + + @ApiProperty({ + example: 'regular, vacation, emergency, sick, parental, etc', + description: 'Type of codes', + }) + type: string; + + @ApiProperty({ + example: 'shift, expense, leave', + description: 'categorie of the related code', + }) + categorie: string; + + @ApiProperty({ + example: '0, 0.72, 1, 1.5, 2', + description: 'modifier number to apply to salary', + }) + modifier: number; + + @ApiProperty({ + example: 'G1, G345, G501, G43, G700', + description: 'codes given by the bank', + }) + bank_code: string; +} \ No newline at end of file diff --git a/src/modules/bank-codes/dtos/update-bank-codes.ts b/src/modules/bank-codes/dtos/update-bank-codes.ts new file mode 100644 index 0000000..658ba81 --- /dev/null +++ b/src/modules/bank-codes/dtos/update-bank-codes.ts @@ -0,0 +1,4 @@ +import { PartialType } from "@nestjs/swagger"; +import { CreateBankCodeDto } from "./create-bank-codes"; + +export class UpdateBankCodeDto extends PartialType(CreateBankCodeDto) {} \ No newline at end of file diff --git a/src/modules/bank-codes/services/bank-codes.services.ts b/src/modules/bank-codes/services/bank-codes.services.ts new file mode 100644 index 0000000..71031de --- /dev/null +++ b/src/modules/bank-codes/services/bank-codes.services.ts @@ -0,0 +1,38 @@ +import { Injectable, NotFoundException } from "@nestjs/common"; +import { PrismaService } from "src/prisma/prisma.service"; +import { CreateBankCodeDto } from "../dtos/create-bank-codes"; +import { BankCodes } from "@prisma/client"; +import { UpdateBankCodeDto } from "../dtos/update-bank-codes"; + +@Injectable() +export class BankCodesService { + constructor(private readonly prisma: PrismaService) {} + + async create(dto: CreateBankCodeDto): Promise{ + return this.prisma.bankCodes.create({ data: dto }) + } + + findAll() { + return this.prisma.bankCodes.findMany(); + } + + async findOne(id: number) { + const bankCode = await this.prisma.bankCodes.findUnique({ where: {id} }); + + if(!bankCode) { + throw new NotFoundException(`Bank Code #${id} not found`); + } + + return bankCode; + } + + async update(id:number, dto: UpdateBankCodeDto) { + await this.prisma.bankCodes.update({ where: { id }, data: dto }); + } + + async remove(id: number) { + await this.findOne(id); + return this.prisma.bankCodes.delete({ where: {id} }); + } + +} \ No newline at end of file diff --git a/src/modules/expense-codes/controllers/expense-codes.controller.ts b/src/modules/expense-codes/controllers/expense-codes.controller.ts deleted file mode 100644 index e120ca8..0000000 --- a/src/modules/expense-codes/controllers/expense-codes.controller.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post, UseGuards } from "@nestjs/common"; -import { ExpenseCodesService } from "../services/expense-codes.service"; -import { ApiTags, ApiBearerAuth, ApiOperation, ApiResponse } from "@nestjs/swagger"; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; -import { ExpenseCodes } from "@prisma/client"; -import { Roles as RoleEnum } from '.prisma/client'; -import { RolesAllowed } from "src/common/decorators/roles.decorators"; -import { CreateExpenseCodeDto } from "../dtos/create-expense-code"; -import { ExpenseCodesEntity } from "../dtos/swagger-entities/expense-codes.entity"; -import { UpdateExpenseCodeDto } from "../dtos/update-expense-code"; - -@ApiTags('Expense Codes') -@ApiBearerAuth('access-token') -@UseGuards(JwtAuthGuard) -@Controller('expense-codes') -export class ExpenseCodesController { - constructor(private readonly expenseCodesService: ExpenseCodesService) {} - - @Post() - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Create expense code' }) - @ApiResponse({ status: 201, description: 'Expense code created',type: ExpenseCodesEntity }) - @ApiResponse({ status: 400, description: 'Incomplete task or invalid data' }) - create(@Body()dto: CreateExpenseCodeDto): Promise { - return this.expenseCodesService.create(dto); - } - - @Get() - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Find all expense codes' }) - @ApiResponse({ status: 201, description: 'List of expense codes found',type: ExpenseCodesEntity, isArray: true }) - @ApiResponse({ status: 400, description: 'List of expense codes not found' }) - findAll(): Promise { - return this.expenseCodesService.findAll(); - } - - @Get(':id') - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Find expense code' }) - @ApiResponse({ status: 201, description: 'Expense code found',type: ExpenseCodesEntity }) - @ApiResponse({ status: 400, description: 'Expense code not found' }) - findOne(@Param('id', ParseIntPipe) id: number): Promise { - return this.expenseCodesService.findOne(id); - } - - @Patch(':id') - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Update expense code' }) - @ApiResponse({ status: 201, description: 'Expense code updated',type: ExpenseCodesEntity }) - @ApiResponse({ status: 400, description: 'Expense code not found' }) - update(@Param('id', ParseIntPipe) id: number, - @Body() dto: UpdateExpenseCodeDto): Promise { - return this.expenseCodesService.update(id,dto); - } - - @Delete(':id') - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Delete expense code' }) - @ApiResponse({ status: 201, description: 'Expense code deleted',type: ExpenseCodesEntity }) - @ApiResponse({ status: 400, description: 'Expense code not found' }) - remove(@Param('id', ParseIntPipe)id: number): Promise { - return this.expenseCodesService.remove(id); - } -} \ No newline at end of file diff --git a/src/modules/expense-codes/dtos/create-expense-code.ts b/src/modules/expense-codes/dtos/create-expense-code.ts deleted file mode 100644 index 7e8bf90..0000000 --- a/src/modules/expense-codes/dtos/create-expense-code.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { IsNotEmpty, IsString } from "class-validator"; - -export class CreateExpenseCodeDto { - - @ApiProperty({ - example:'mileage, overnight, etc...', - description: 'Type of expenses for an account perception', - }) - @IsString() - @IsNotEmpty() - expense_type: string; - - @ApiProperty({ - example: 'G500, G501, etc...', - description: 'bank`s code related to the type of expense', - }) - @IsString() - @IsNotEmpty() - bank_code: string; -} \ No newline at end of file diff --git a/src/modules/expense-codes/dtos/swagger-entities/expense-codes.entity.ts b/src/modules/expense-codes/dtos/swagger-entities/expense-codes.entity.ts deleted file mode 100644 index 08a5aec..0000000 --- a/src/modules/expense-codes/dtos/swagger-entities/expense-codes.entity.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ApiProperty } from "@nestjs/swagger"; - -export class ExpenseCodesEntity { - @ApiProperty({ - example: 1, - description: 'Unique ID of a expense-code (auto-generated)', - }) - id: number; - - @ApiProperty({ - example: 'Mileage', - description: 'Type of expenses for an account perception', - }) - shift_type: string; - - @ApiProperty({ - example: 'G501', - description: 'bank`s code related to the type of expense', - }) - bank_code: string; -} \ No newline at end of file diff --git a/src/modules/expense-codes/dtos/update-expense-code.ts b/src/modules/expense-codes/dtos/update-expense-code.ts deleted file mode 100644 index f2413e3..0000000 --- a/src/modules/expense-codes/dtos/update-expense-code.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { PartialType } from "@nestjs/swagger"; -import { CreateExpenseCodeDto } from "./create-expense-code"; - -export class UpdateExpenseCodeDto extends PartialType(CreateExpenseCodeDto) {} \ No newline at end of file diff --git a/src/modules/expense-codes/expense-codes.module.ts b/src/modules/expense-codes/expense-codes.module.ts deleted file mode 100644 index 92e5d77..0000000 --- a/src/modules/expense-codes/expense-codes.module.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Module } from "@nestjs/common"; -import { PrismaService } from "src/prisma/prisma.service"; -import { ExpenseCodesController } from "./controllers/expense-codes.controller"; -import { ExpenseCodesService } from "./services/expense-codes.service"; - -@Module({ - controllers: [ExpenseCodesController], - providers: [ExpenseCodesService, PrismaService] -}) - -export class ExpenseCodesModule {} \ No newline at end of file diff --git a/src/modules/expense-codes/services/expense-codes.service.ts b/src/modules/expense-codes/services/expense-codes.service.ts deleted file mode 100644 index 4428aaa..0000000 --- a/src/modules/expense-codes/services/expense-codes.service.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { Injectable, NotFoundException } from "@nestjs/common"; -import { PrismaService } from "src/prisma/prisma.service"; -import { CreateExpenseCodeDto } from "../dtos/create-expense-code"; -import { ExpenseCodes } from "@prisma/client"; -import { UpdateExpenseCodeDto } from "../dtos/update-expense-code"; - -@Injectable() -export class ExpenseCodesService { - constructor(private readonly prisma: PrismaService) {} - - async create(dto: CreateExpenseCodeDto): Promise { - const { expense_type, bank_code } = dto; - return this.prisma.expenseCodes.create({ - data: { expense_type, bank_code }, - include: { - expense: { - include: { - timesheet: { - include: { - employee: { include: { user: true } }, - }, - }, - }, - }, - }, - }); - } - - findAll(): Promise { - return this.prisma.expenseCodes.findMany({ - include: { - expense: { - include: { - timesheet: { - include: { - employee: { - include: { user: true } - }, - }, - }, - }, - }, - }, - }); - } - - async findOne(id: number): Promise { - const record = await this.prisma.expenseCodes.findUnique({ - where: { id }, - include: { - expense: { - include: { - timesheet: { - include: { - employee: { - include: { user:true }, - }, - }, - }, - }, - }, - }, - }); - if(!record) { - throw new NotFoundException(`ExpenseCode #${id} not found`); - } - return record; - } - - async update(id: number, dto: UpdateExpenseCodeDto): Promise { - await this.findOne(id); - const { expense_type, bank_code } = dto; - return this.prisma.expenseCodes.update({ - where: { id }, - data: { - ...(expense_type !== undefined && { expense_type }), - ...(bank_code !== undefined && { bank_code }), - }, - include: { - expense: { - include: { - timesheet: { - include: { - employee: { - include: { user: true }, - }, - }, - }, - }, - }, - }, - }); - } - - async remove(id: number): Promise { - await this.findOne(id); - return this.prisma.expenseCodes.delete({ where: { id } }); - } -} \ No newline at end of file diff --git a/src/modules/expenses/dtos/create-expense.ts b/src/modules/expenses/dtos/create-expense.ts index b2037b8..a9a02c4 100644 --- a/src/modules/expenses/dtos/create-expense.ts +++ b/src/modules/expenses/dtos/create-expense.ts @@ -1,61 +1,32 @@ -import { ApiProperty } from "@nestjs/swagger"; import { Type } from "class-transformer"; import { IsBoolean, IsDate, IsDateString, IsInt, IsOptional, IsString } from "class-validator"; export class CreateExpenseDto { - @ApiProperty({ - example: 'Th3F3110w5h1pX2024', - description: 'ID number for a set timesheet', - }) @Type(()=> Number) @IsInt() timesheet_id: number; - @ApiProperty({ - example: '0n3R1n962Ru13xX', - description: 'ID number of an expense code (link with shift-codes)', - }) @Type(() => Number) @IsInt() - expense_code_id: number; + bank_code_id: number; - @ApiProperty({ - example: '20/10/3018', - description: 'Date where the expense was made', - }) @IsDateString() @Type(() => Date) @IsDate() date: Date; - @ApiProperty({ - example: '280 000 000,00', - description: 'Amount of the expense', - }) @Type(() => Number) @IsInt() amount: number - @ApiProperty({ - example:'Spent for mileage between A and B', - description:'explain`s why the expense was made' - }) @IsString() description?: string; - @ApiProperty({ - example: 'True or False or Pending or Denied or Cancelled or Escalated', - description: 'Expense`s approval status', - }) @IsOptional() @IsBoolean() is_approved?: boolean; - @ApiProperty({ - example:'Asked X to go there as an emergency response', - description:'Supervisro`s justification for the spending of an employee' - }) @IsString() supervisor_comment?: string; } diff --git a/src/modules/expenses/dtos/swagger-entities/expenses.entity.ts b/src/modules/expenses/dtos/swagger-entities/expenses.entity.ts index 2fbdbcd..3cd3983 100644 --- a/src/modules/expenses/dtos/swagger-entities/expenses.entity.ts +++ b/src/modules/expenses/dtos/swagger-entities/expenses.entity.ts @@ -16,9 +16,9 @@ export class ExpenseEntity { @ApiProperty({ example: 7, - description: 'ID number of an expense code (link with expense-codes)', + description: 'ID number of an bank code (link with bank-codes)', }) - expense: number; + bank_code_id: number; @ApiProperty({ example: '3018-10-20T00:00:00.000Z', diff --git a/src/modules/expenses/services/expenses.service.ts b/src/modules/expenses/services/expenses.service.ts index 9f8c0e2..a5b00b2 100644 --- a/src/modules/expenses/services/expenses.service.ts +++ b/src/modules/expenses/services/expenses.service.ts @@ -9,17 +9,17 @@ export class ExpensesService { constructor(private readonly prisma: PrismaService) {} async create(dto: CreateExpenseDto): Promise { - const { timesheet_id, expense_code_id, date, amount, + const { timesheet_id, bank_code_id, date, amount, description, is_approved,supervisor_comment} = dto; return this.prisma.expenses.create({ - data: { timesheet_id, expense_code_id,date,amount,description,is_approved,supervisor_comment}, + data: { timesheet_id, bank_code_id,date,amount,description,is_approved,supervisor_comment}, include: { timesheet: { include: { employee: { include: { user: true } }, }, }, - expense_code: true, + bank_code: true, }, }); } @@ -45,7 +45,7 @@ export class ExpensesService { employee: { include: { user:true } }, }, }, - expense_code: true, + bank_code: true, }, }); if (!expense) { @@ -56,13 +56,13 @@ export class ExpensesService { async update(id: number, dto: UpdateExpenseDto): Promise { await this.findOne(id); - const { timesheet_id, expense_code_id, date, amount, + const { timesheet_id, bank_code_id, date, amount, description, is_approved, supervisor_comment} = dto; return this.prisma.expenses.update({ where: { id }, data: { ...(timesheet_id !== undefined && { timesheet_id}), - ...(expense_code_id !== undefined && { expense_code_id }), + ...(bank_code_id !== undefined && { bank_code_id }), ...(date !== undefined && { date }), ...(amount !== undefined && { amount }), ...(description !== undefined && { description }), @@ -77,7 +77,7 @@ export class ExpensesService { }, }, }, - expense_code: true, + bank_code: true, }, }); } @@ -116,7 +116,7 @@ export class ExpensesService { data: expensesToArchive.map(exp => ({ expense_id: exp.id, timesheet_id: exp.timesheet_id, - expense_code_id: exp.expense_code_id, + bank_code_id: exp.bank_code_id, date: exp.date, amount: exp.amount, attachement: exp.attachement, diff --git a/src/modules/shift-codes/controllers/shift-codes.controller.ts b/src/modules/shift-codes/controllers/shift-codes.controller.ts deleted file mode 100644 index 0b34a68..0000000 --- a/src/modules/shift-codes/controllers/shift-codes.controller.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post, UseGuards } from "@nestjs/common"; -import { ShiftCodesService } from "../services/shift-codes.service"; -import { CreateShiftCodeDto } from "../dtos/create-shift-codes.dto"; -import { ShiftCodes } from "@prisma/client"; -import { UpdateShiftCodeDto } from "../dtos/update-shift-codes.dto"; -import { RolesAllowed } from "src/common/decorators/roles.decorators"; -import { Roles as RoleEnum } from '.prisma/client'; -import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; -import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; -import { ShiftCodesEntity } from "../dtos/swagger-entities/shift-codes.entity"; - -@ApiTags('Shift Codes') -@ApiBearerAuth('access-token') -@UseGuards(JwtAuthGuard) -@Controller('shift-codes') -export class ShiftCodesController { - constructor(private readonly shiftCodesService: ShiftCodesService) {} - - @Post() - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Create shift code' }) - @ApiResponse({ status: 201, description: 'Shift code created',type: ShiftCodesEntity }) - @ApiResponse({ status: 400, description: 'Incomplete task or invalid data' }) - create(@Body()dto: CreateShiftCodeDto): Promise { - return this.shiftCodesService.create(dto); - } - - @Get() - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Find all shift codes' }) - @ApiResponse({ status: 201, description: 'List of shift codes found',type: ShiftCodesEntity, isArray: true }) - @ApiResponse({ status: 400, description: 'List of shift codes not found' }) - findAll(): Promise { - return this.shiftCodesService.findAll(); - } - - @Get(':id') - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Find shift code' }) - @ApiResponse({ status: 201, description: 'Shift code found',type: ShiftCodesEntity }) - @ApiResponse({ status: 400, description: 'Shift code not found' }) - findOne(@Param('id', ParseIntPipe) id: number): Promise { - return this.shiftCodesService.findOne(id); - } - - @Patch(':id') - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Update shift code' }) - @ApiResponse({ status: 201, description: 'Shift code updated',type: ShiftCodesEntity }) - @ApiResponse({ status: 400, description: 'Shift code not found' }) - update(@Param('id', ParseIntPipe) id: number, - @Body() dto: UpdateShiftCodeDto): Promise { - return this.shiftCodesService.update(id,dto); - } - - @Delete(':id') - @RolesAllowed(RoleEnum.ACCOUNTING, RoleEnum.ADMIN, RoleEnum.HR) - @ApiOperation({ summary: 'Delete shift code' }) - @ApiResponse({ status: 201, description: 'Shift code deleted',type: ShiftCodesEntity }) - @ApiResponse({ status: 400, description: 'Shift code not found' }) - remove(@Param('id', ParseIntPipe)id: number): Promise { - return this.shiftCodesService.remove(id); - } -} diff --git a/src/modules/shift-codes/dtos/create-shift-codes.dto.ts b/src/modules/shift-codes/dtos/create-shift-codes.dto.ts deleted file mode 100644 index 5cdff72..0000000 --- a/src/modules/shift-codes/dtos/create-shift-codes.dto.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { IsNotEmpty, IsString } from "class-validator"; - -export class CreateShiftCodeDto { - - @ApiProperty({ - example: 'Regular or Night or Emergency, etc...', - description: 'Type of shifts for an account perception', - }) - @IsString() - @IsNotEmpty() - shift_type: string; - - @ApiProperty({ - example: 'G1, G2, G3, etc...', - description: 'bank`s code related to the type of shift', - }) - @IsString() - @IsNotEmpty() - bank_code: string; -} \ No newline at end of file diff --git a/src/modules/shift-codes/dtos/swagger-entities/shift-codes.entity.ts b/src/modules/shift-codes/dtos/swagger-entities/shift-codes.entity.ts deleted file mode 100644 index 6a90b6b..0000000 --- a/src/modules/shift-codes/dtos/swagger-entities/shift-codes.entity.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; - -export class ShiftCodesEntity { - @ApiProperty({ - example: 1, - description: 'Unique ID of a shift-code (auto-generated)', - }) - id: number; - - @ApiProperty({ - example: 'Night', - description: 'Type of shifts for an account perception', - }) - shift_type: string; - - @ApiProperty({ - example: 'G2', - description: 'bank`s code related to the type of shift', - }) - bank_code: string; -} diff --git a/src/modules/shift-codes/dtos/update-shift-codes.dto.ts b/src/modules/shift-codes/dtos/update-shift-codes.dto.ts deleted file mode 100644 index bb956c6..0000000 --- a/src/modules/shift-codes/dtos/update-shift-codes.dto.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { PartialType } from '@nestjs/swagger'; -import { CreateShiftCodeDto } from './create-shift-codes.dto'; - -export class UpdateShiftCodeDto extends PartialType(CreateShiftCodeDto) {} diff --git a/src/modules/shift-codes/services/shift-codes.service.ts b/src/modules/shift-codes/services/shift-codes.service.ts deleted file mode 100644 index c88b958..0000000 --- a/src/modules/shift-codes/services/shift-codes.service.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { Injectable, NotFoundException } from "@nestjs/common"; -import { PrismaService } from "src/prisma/prisma.service"; -import { CreateShiftCodeDto } from "../dtos/create-shift-codes.dto"; -import { ShiftCodes } from "@prisma/client"; -import { UpdateShiftCodeDto } from "../dtos/update-shift-codes.dto"; - -@Injectable() -export class ShiftCodesService { - constructor(private readonly prisma: PrismaService) {} - - async create(dto: CreateShiftCodeDto): Promise { - const { shift_type, bank_code } = dto; - return this.prisma.shiftCodes.create({ - data: { shift_type, bank_code }, - include: { - shift: { - include: { - timesheet: { - include: { - employee: { - include: { - user: true, - }, - }, - }, - }, - }, - }, - }, - }); - } - - findAll(): Promise { - return this.prisma.shiftCodes.findMany({ - include: { - shift: { - include: { - timesheet: { - include: { - employee: { - include: { - user: true - } - } - } - } - }, - }, - }, - }); - } - - async findOne(id: number): Promise { - const record = await this.prisma.shiftCodes.findUnique({ - where: { id }, - include: { - shift: { - include: { - timesheet: { - include: { - employee: { - include: { - user:true, - } - } - } - } - } - } - } - }); - if(!record) { - throw new NotFoundException(`ShiftCode #${id} not found`); - } - return record; - } - - async update(id: number, dto: UpdateShiftCodeDto): Promise { - await this.findOne(id); - const { shift_type, bank_code } = dto; - return this.prisma.shiftCodes.update({ - where: { id }, - data: { - ...(shift_type !== undefined && { shift_type }), - ...(bank_code !== undefined && { bank_code }), - }, - include: { - shift: { - include: { - timesheet: { - include: { - employee: { - include: { - user: true - } - } - } - }, - }, - }, - }, - }); - } - - async remove(id:number): Promise{ - await this.findOne(id); - return this.prisma.shiftCodes.delete({ where: { id }}); - } -} \ No newline at end of file diff --git a/src/modules/shift-codes/shift-codes.module.ts b/src/modules/shift-codes/shift-codes.module.ts deleted file mode 100644 index a8574ae..0000000 --- a/src/modules/shift-codes/shift-codes.module.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Module } from "@nestjs/common"; -import { ShiftCodesController } from "./controllers/shift-codes.controller"; -import { ShiftCodesService } from "./services/shift-codes.service"; -import { PrismaService } from "src/prisma/prisma.service"; - -@Module({ - controllers: [ShiftCodesController], - providers: [ShiftCodesService, PrismaService], -}) - -export class ShiftCodesModule {} \ No newline at end of file diff --git a/src/modules/shifts/dtos/create-shifts.dto.ts b/src/modules/shifts/dtos/create-shifts.dto.ts index f17403d..0e5241d 100644 --- a/src/modules/shifts/dtos/create-shifts.dto.ts +++ b/src/modules/shifts/dtos/create-shifts.dto.ts @@ -1,56 +1,31 @@ -import { ApiProperty } from "@nestjs/swagger"; import { Type } from "class-transformer"; import { IsDate, IsDateString, IsInt, IsString } from "class-validator"; export class CreateShiftDto { - @ApiProperty({ - example: 'Th3F3110w5h1pX2024', - description: 'ID number for a set timesheet', - }) @Type(() => Number) @IsInt() timesheet_id: number; - @ApiProperty({ - example: '0n3R1n962Ru13xX', - description: 'ID number of a shift code (link with shift-codes)', - }) @Type(() => Number) @IsInt() - shift_code_id: number; + bank_code_id: number; - @ApiProperty({ - example: '20/10/3018', - description: 'Date where the shift takes place', - }) @IsDateString() @Type(() => Date) @IsDate() date: Date; - @ApiProperty({ - example: '08:00', - description: 'Start time of the said shift', - }) @IsDateString() @Type(() => Date) @IsDate() start_time: Date; - @ApiProperty({ - example: '17:00', - description: 'End time of the said shift', - }) @IsDateString() @Type(() => Date) @IsDate() end_time: Date; - @ApiProperty({ - example:'Called for an emergency at X` place', - description:'justify the purpose of the shift' - }) @IsString() description: string; } diff --git a/src/modules/shifts/dtos/swagger-entities/shift.entity.ts b/src/modules/shifts/dtos/swagger-entities/shift.entity.ts index 787dfea..54efc06 100644 --- a/src/modules/shifts/dtos/swagger-entities/shift.entity.ts +++ b/src/modules/shifts/dtos/swagger-entities/shift.entity.ts @@ -15,9 +15,9 @@ export class ShiftEntity { @ApiProperty({ example: 7, - description: 'ID number of a shift code (link with shift-codes)', + description: 'ID number of a shift code (link with bank-codes)', }) - shift_code_id: number; + bank_code_id: number; @ApiProperty({ example: '3018-10-20T00:00:00.000Z', diff --git a/src/modules/shifts/services/shifts.service.ts b/src/modules/shifts/services/shifts.service.ts index 2844bcb..e7c3942 100644 --- a/src/modules/shifts/services/shifts.service.ts +++ b/src/modules/shifts/services/shifts.service.ts @@ -9,16 +9,16 @@ export class ShiftsService { constructor(private readonly prisma: PrismaService) {} async create(dto: CreateShiftDto): Promise { - const { timesheet_id, shift_code_id, date, start_time, end_time } = dto; + const { timesheet_id, bank_code_id, date, start_time, end_time } = dto; return this.prisma.shifts.create({ - data: { timesheet_id, shift_code_id, date, start_time, end_time }, + data: { timesheet_id, bank_code_id, date, start_time, end_time }, include: { timesheet: { include: { employee: { include: { user: true } }, }, }, - shift_code: true, + bank_code: true, }, }); } @@ -48,7 +48,7 @@ export class ShiftsService { }, }, }, - shift_code: true, + bank_code: true, }, }); if(!shift) { @@ -59,12 +59,12 @@ export class ShiftsService { async update(id: number, dto: UpdateShiftsDto): Promise { await this.findOne(id); - const { timesheet_id, shift_code_id, date,start_time,end_time} = dto; + const { timesheet_id, bank_code_id, date,start_time,end_time} = dto; return this.prisma.shifts.update({ where: { id }, data: { ...(timesheet_id !== undefined && { timesheet_id }), - ...(shift_code_id !== undefined && { shift_code_id }), + ...(bank_code_id !== undefined && { bank_code_id }), ...(date !== undefined && { date }), ...(start_time !== undefined && { start_time }), ...(end_time !== undefined && { end_time }), @@ -77,7 +77,7 @@ export class ShiftsService { }, }, }, - shift_code: true, + bank_code: true, }, }); } @@ -115,7 +115,7 @@ export class ShiftsService { data: shiftsToArchive.map(shift => ({ shift_id: shift.id, timesheet_id: shift.timesheet_id, - shift_code_id: shift.shift_code_id, + bank_code_id: shift.bank_code_id, description: shift.description ?? undefined, date: shift.date, start_time: shift.start_time,