From 2b033de91b7a2e7cd47efe1705be7e8a8b0266ce Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Thu, 30 Oct 2025 13:57:16 -0400 Subject: [PATCH] fix(imports): ajusted imports to remove relative paths --- .../controllers/expense.controller.ts | 11 ++--- .../expenses/dtos/expense-update.dto.ts | 2 +- .../services/expense-upsert.service.ts | 41 ++++--------------- .../services/expenses-archival.service.ts | 2 +- .../controller/schedule-presets.controller.ts | 16 ++++---- .../dtos/create-schedule-presets.dto.ts | 2 +- .../schedule-presets.module.ts | 12 +++--- ...ice.ts => schedule-presets-get.service.ts} | 4 +- ....ts => schedule-presets-upsert.service.ts} | 15 +++---- .../shifts/controllers/shift.controller.ts | 8 ++-- .../shifts/dtos/shift-update.dto.ts | 2 +- .../shifts/services/shifts-get.service.ts | 8 ++-- .../shifts/services/shifts-upsert.service.ts | 30 +++++++------- .../time-tracker/shifts/shifts.module.ts | 7 ++-- .../controllers/timesheet.controller.ts | 4 +- .../services/timesheet-approval.service.ts | 4 +- .../timesheet-get-overview.service.ts | 6 +-- .../timesheets/timesheets.module.ts | 8 ++-- .../time-and-attendance.module.ts | 8 ++-- .../utils/constants.utils.ts | 2 +- src/time-and-attendance/utils/type.utils.ts | 26 +++++++++--- 21 files changed, 106 insertions(+), 112 deletions(-) rename src/time-and-attendance/modules/time-tracker/schedule-presets/services/{schedule-presets-query.service.ts => schedule-presets-get.service.ts} (92%) rename src/time-and-attendance/modules/time-tracker/schedule-presets/services/{schedule-presets-command.service.ts => schedule-presets-upsert.service.ts} (95%) diff --git a/src/time-and-attendance/modules/expenses/controllers/expense.controller.ts b/src/time-and-attendance/modules/expenses/controllers/expense.controller.ts index 47dca6b..572972d 100644 --- a/src/time-and-attendance/modules/expenses/controllers/expense.controller.ts +++ b/src/time-and-attendance/modules/expenses/controllers/expense.controller.ts @@ -1,7 +1,8 @@ -import { Body, Controller, Delete, Param, ParseIntPipe, Patch, Post } from "@nestjs/common"; -import { CreateResult, ExpenseUpsertService, UpdateResult } from "../services/expense-upsert.service"; +import { Controller, Post, Param, ParseIntPipe, Body, Patch, Delete } from "@nestjs/common"; +import { CreateExpenseResult, UpdateExpenseResult } from "src/time-and-attendance/utils/type.utils"; +import { ExpenseUpsertService } from "src/time-and-attendance/modules/expenses/services/expense-upsert.service"; import { updateExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-update.dto"; -import { ExpenseDto } from "../dtos/expense-create.dto"; +import { ExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-create.dto"; @Controller('expense') @@ -11,13 +12,13 @@ export class ExpenseController { @Post(':timesheet_id') create( @Param('timesheet_id', ParseIntPipe) timesheet_id: number, - @Body() dto: ExpenseDto): Promise{ + @Body() dto: ExpenseDto): Promise{ return this.upsert_service.createExpense(timesheet_id, dto); } @Patch() update( - @Body() body: { update :{ id: number; dto: updateExpenseDto }}): Promise{ + @Body() body: { update :{ id: number; dto: updateExpenseDto }}): Promise{ return this.upsert_service.updateExpense(body.update); } diff --git a/src/time-and-attendance/modules/expenses/dtos/expense-update.dto.ts b/src/time-and-attendance/modules/expenses/dtos/expense-update.dto.ts index 6108682..829f9c9 100644 --- a/src/time-and-attendance/modules/expenses/dtos/expense-update.dto.ts +++ b/src/time-and-attendance/modules/expenses/dtos/expense-update.dto.ts @@ -1,5 +1,5 @@ import { OmitType, PartialType } from "@nestjs/swagger"; -import { ExpenseDto } from "./expense-create.dto"; +import { ExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-create.dto"; export class updateExpenseDto extends PartialType ( OmitType(ExpenseDto, ['is_approved', 'timesheet_id'] as const) diff --git a/src/time-and-attendance/modules/expenses/services/expense-upsert.service.ts b/src/time-and-attendance/modules/expenses/services/expense-upsert.service.ts index b2e8766..64390af 100644 --- a/src/time-and-attendance/modules/expenses/services/expense-upsert.service.ts +++ b/src/time-and-attendance/modules/expenses/services/expense-upsert.service.ts @@ -1,18 +1,12 @@ +import { CreateExpenseResult, UpdateExpensePayload, UpdateExpenseResult, DeleteExpenseResult, NormalizedExpense } from "src/time-and-attendance/utils/type.utils"; import { toDateFromString, toStringFromDate } from "src/time-and-attendance/utils/date-time.utils"; import { Injectable, NotFoundException } from "@nestjs/common"; -import { updateExpenseDto } from "../dtos/expense-update.dto"; -import { GetExpenseDto } from "../dtos/expense-get.dto"; +import { expense_select } from "src/time-and-attendance/utils/selects.utils"; import { PrismaService } from "src/prisma/prisma.service"; -import { ExpenseDto } from "../dtos/expense-create.dto"; -import { Prisma } from "@prisma/client"; +import { GetExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-get.dto"; +import { ExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-create.dto"; -type Normalized = { date: Date; comment: string; supervisor_comment?: string; }; - -export type CreateResult = { ok: true; data: GetExpenseDto } | { ok: false; error: any }; -export type UpdatePayload = { id: number; dto: updateExpenseDto }; -export type UpdateResult = { ok: true; id: number; data: GetExpenseDto } | { ok: false; id: number; error: any }; -export type DeleteResult = { ok: true; id: number; } | { ok: false; id: number; error: any }; @Injectable() export class ExpenseUpsertService { @@ -21,7 +15,7 @@ export class ExpenseUpsertService { //_________________________________________________________________ // CREATE //_________________________________________________________________ - async createExpense(timesheet_id: number, dto: ExpenseDto): Promise { + async createExpense(timesheet_id: number, dto: ExpenseDto): Promise { try { //normalize strings and dates const normed_expense = this.normalizeExpenseDto(dto); @@ -71,7 +65,7 @@ export class ExpenseUpsertService { //_________________________________________________________________ // UPDATE //_________________________________________________________________ - async updateExpense({id, dto}: UpdatePayload): Promise { + async updateExpense({id, dto}: UpdateExpensePayload): Promise { try { //checks for modifications const data: Record = {}; @@ -117,7 +111,7 @@ export class ExpenseUpsertService { //_________________________________________________________________ // DELETE //_________________________________________________________________ - async deleteExpense(expense_id: number): Promise { + async deleteExpense(expense_id: number): Promise { try { await this.prisma.$transaction(async (tx) => { const expense = await tx.expenses.findUnique({ @@ -139,7 +133,7 @@ export class ExpenseUpsertService { // LOCAL HELPERS //_________________________________________________________________ //makes sure that comments are the right length the date is of Date type - private normalizeExpenseDto(dto: ExpenseDto): Normalized { + private normalizeExpenseDto(dto: ExpenseDto): NormalizedExpense { const date = toDateFromString(dto.date); const comment = this.truncate280(dto.comment); const supervisor_comment = @@ -161,21 +155,4 @@ export class ExpenseUpsertService { if (Number.isNaN(parsed)) throw new Error(`Invalid value : ${value} for ${field}`); return parsed; }; - - -} - - - - export const expense_select = { - id: true, - timesheet_id: true, - bank_code_id: true, - attachment: true, - date: true, - amount: true, - mileage: true, - comment: true, - supervisor_comment: true, - is_approved: true, - } satisfies Prisma.ExpensesSelect; \ No newline at end of file +} \ No newline at end of file diff --git a/src/time-and-attendance/modules/expenses/services/expenses-archival.service.ts b/src/time-and-attendance/modules/expenses/services/expenses-archival.service.ts index fc17c63..0c354d6 100644 --- a/src/time-and-attendance/modules/expenses/services/expenses-archival.service.ts +++ b/src/time-and-attendance/modules/expenses/services/expenses-archival.service.ts @@ -1,6 +1,6 @@ -import { Injectable } from "@nestjs/common"; import { ExpensesArchive } from "@prisma/client"; import { PrismaService } from "src/prisma/prisma.service"; +import { Injectable } from "@nestjs/common"; @Injectable() export class ExpensesArchivalService { diff --git a/src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller.ts b/src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller.ts index bd05224..a9d5c87 100644 --- a/src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller.ts +++ b/src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller.ts @@ -1,16 +1,16 @@ import { Controller, Param, Query, Body, Get, Post, BadRequestException, ParseIntPipe, Delete, Patch } from "@nestjs/common"; -import { SchedulePresetsCommandService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-command.service"; +import { SchedulePresetsUpsertService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-upsert.service"; import { SchedulePresetsApplyService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-apply.service"; -import { SchedulePresetsQueryService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service"; +import { SchedulePresetsGetService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-get.service"; import { SchedulePresetsUpdateDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/update-schedule-presets.dto"; import { SchedulePresetsDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto"; @Controller('schedule-presets') export class SchedulePresetsController { constructor( - private readonly commandService: SchedulePresetsCommandService, + private readonly upsertService: SchedulePresetsUpsertService, private readonly applyPresetsService: SchedulePresetsApplyService, - private readonly queryService: SchedulePresetsQueryService, + private readonly getService: SchedulePresetsGetService, ){} //used to create a schedule preset @@ -19,7 +19,7 @@ export class SchedulePresetsController { @Param('employee_id', ParseIntPipe) employee_id: number, @Body() dto: SchedulePresetsDto, ) { - return await this.commandService.createPreset(employee_id, dto); + return await this.upsertService.createPreset(employee_id, dto); } //used to update an already existing schedule preset @@ -28,7 +28,7 @@ export class SchedulePresetsController { @Param('preset_id', ParseIntPipe) preset_id: number, @Body() dto: SchedulePresetsUpdateDto, ) { - return await this.commandService.updatePreset(preset_id, dto); + return await this.upsertService.updatePreset(preset_id, dto); } //used to delete a schedule preset @@ -36,7 +36,7 @@ export class SchedulePresetsController { async deletePreset( @Param('preset_id') preset_id: number, ) { - return await this.commandService.deletePreset(preset_id); + return await this.upsertService.deletePreset(preset_id); } @@ -45,7 +45,7 @@ export class SchedulePresetsController { async findListById( @Param('employee_id', ParseIntPipe) employee_id: number, ) { - return this.queryService.findSchedulePresets(employee_id); + return this.getService.getSchedulePresets(employee_id); } diff --git a/src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto.ts b/src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto.ts index cb1c512..86d7704 100644 --- a/src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto.ts +++ b/src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto.ts @@ -1,5 +1,5 @@ import { ArrayMinSize, IsArray, IsBoolean, IsOptional, IsString } from "class-validator"; -import { SchedulePresetShiftsDto } from "./create-schedule-preset-shifts.dto"; +import { SchedulePresetShiftsDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-preset-shifts.dto"; export class SchedulePresetsDto { @IsString() diff --git a/src/time-and-attendance/modules/time-tracker/schedule-presets/schedule-presets.module.ts b/src/time-and-attendance/modules/time-tracker/schedule-presets/schedule-presets.module.ts index 1a8f9bf..ac6c595 100644 --- a/src/time-and-attendance/modules/time-tracker/schedule-presets/schedule-presets.module.ts +++ b/src/time-and-attendance/modules/time-tracker/schedule-presets/schedule-presets.module.ts @@ -1,6 +1,6 @@ -import { SchedulePresetsCommandService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-command.service"; +import { SchedulePresetsUpsertService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-upsert.service"; import { SchedulePresetsApplyService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-apply.service"; -import { SchedulePresetsQueryService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service"; +import { SchedulePresetsGetService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-get.service"; import { SchedulePresetsController } from "src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller"; import { SharedModule } from "src/time-and-attendance/modules/shared/shared.module"; import { Module } from "@nestjs/common"; @@ -10,13 +10,13 @@ import { Module } from "@nestjs/common"; imports: [SharedModule], controllers: [SchedulePresetsController], providers: [ - SchedulePresetsCommandService, - SchedulePresetsQueryService, + SchedulePresetsUpsertService, + SchedulePresetsGetService, SchedulePresetsApplyService, ], exports:[ - SchedulePresetsCommandService, - SchedulePresetsQueryService, + SchedulePresetsUpsertService, + SchedulePresetsGetService, SchedulePresetsApplyService, ], }) export class SchedulePresetsModule {} \ No newline at end of file diff --git a/src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service.ts b/src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-get.service.ts similarity index 92% rename from src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service.ts rename to src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-get.service.ts index b16911c..e73227d 100644 --- a/src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service.ts +++ b/src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-get.service.ts @@ -4,10 +4,10 @@ import { Injectable } from "@nestjs/common"; import { Prisma } from "@prisma/client"; @Injectable() -export class SchedulePresetsQueryService { +export class SchedulePresetsGetService { constructor( private readonly prisma: PrismaService ){} - async findSchedulePresets(employee_id: number): Promise { + async getSchedulePresets(employee_id: number): Promise { try { const presets = await this.prisma.schedulePresets.findMany({ where: { employee_id }, diff --git a/src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-command.service.ts b/src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-upsert.service.ts similarity index 95% rename from src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-command.service.ts rename to src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-upsert.service.ts index cb35378..da45941 100644 --- a/src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-command.service.ts +++ b/src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-upsert.service.ts @@ -1,16 +1,13 @@ import { Injectable, BadRequestException, NotFoundException, ConflictException } from "@nestjs/common"; +import { CreatePresetResult, DeletePresetResult, UpdatePresetResult } from "src/time-and-attendance/utils/type.utils"; import { SchedulePresetsDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto"; import { BankCodesResolver } from "src/time-and-attendance/modules/shared/utils/resolve-bank-type-id.utils"; import { Prisma, Weekday } from "@prisma/client"; -import { PrismaService } from "src/prisma/prisma.service"; import { toHHmmFromDate } from "src/time-and-attendance/utils/date-time.utils"; - -type DeleteResult = { ok: true; id: number; } | { ok: false; id: number; error: any }; -type CreateResult = { ok: true; } | { ok: false; error: any }; -type UpdateResult = { ok: true; id: number; data: SchedulePresetsDto } | { ok: false; id: number; error: any }; +import { PrismaService } from "src/prisma/prisma.service"; @Injectable() -export class SchedulePresetsCommandService { +export class SchedulePresetsUpsertService { constructor( private readonly prisma: PrismaService, private readonly typeResolver : BankCodesResolver, @@ -18,7 +15,7 @@ export class SchedulePresetsCommandService { //_________________________________________________________________ // CREATE //_________________________________________________________________ - async createPreset( employee_id: number, dto: SchedulePresetsDto): Promise { + async createPreset( employee_id: number, dto: SchedulePresetsDto): Promise { try { const shifts_data = await this.resolveAndBuildPresetShifts(dto); if(!shifts_data) throw new BadRequestException(`Employee with id: ${employee_id} or dto not found`); @@ -49,7 +46,7 @@ export class SchedulePresetsCommandService { //_________________________________________________________________ // UPDATE //_________________________________________________________________ - async updatePreset( preset_id: number, dto: SchedulePresetsDto ): Promise { + async updatePreset( preset_id: number, dto: SchedulePresetsDto ): Promise { try { const existing = await this.prisma.schedulePresets.findFirst({ where: { id: preset_id }, @@ -137,7 +134,7 @@ export class SchedulePresetsCommandService { //_________________________________________________________________ // DELETE //_________________________________________________________________ - async deletePreset( preset_id: number ): Promise { + async deletePreset( preset_id: number ): Promise { try { await this.prisma.$transaction(async (tx) => { const preset = await tx.schedulePresets.findFirst({ diff --git a/src/time-and-attendance/modules/time-tracker/shifts/controllers/shift.controller.ts b/src/time-and-attendance/modules/time-tracker/shifts/controllers/shift.controller.ts index 6c4968c..6928cc8 100644 --- a/src/time-and-attendance/modules/time-tracker/shifts/controllers/shift.controller.ts +++ b/src/time-and-attendance/modules/time-tracker/shifts/controllers/shift.controller.ts @@ -1,8 +1,8 @@ import { BadRequestException, Body, Controller, Delete, Param, Patch, Post } from "@nestjs/common"; -import { CreateResult, UpdateResult } from "src/time-and-attendance/utils/type.utils"; +import { CreateShiftResult, UpdateShiftResult } from "src/time-and-attendance/utils/type.utils"; import { ShiftsUpsertService } from "src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service"; import { UpdateShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-update.dto"; -import { ShiftDto } from "../dtos/shift-create.dto"; +import { ShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-create.dto"; @Controller('shift') @@ -11,7 +11,7 @@ export class ShiftController { @Post('create') createBatch( - @Body()dtos: ShiftDto[]): Promise { + @Body()dtos: ShiftDto[]): Promise { const list = Array.isArray(dtos) ? dtos : []; if(list.length === 0) throw new BadRequestException('Body is missing or invalid (create shifts)'); return this.upsert_service.createShifts(dtos) @@ -21,7 +21,7 @@ export class ShiftController { //change Body to receive dtos @Patch('update') updateBatch( - @Body() dtos: UpdateShiftDto[]): Promise{ + @Body() dtos: UpdateShiftDto[]): Promise{ const list = Array.isArray(dtos) ? dtos: []; if(list.length === 0) throw new BadRequestException('Body is missing or invalid (update shifts)'); return this.upsert_service.updateShifts(dtos); diff --git a/src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-update.dto.ts b/src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-update.dto.ts index 99645cb..ce16f8e 100644 --- a/src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-update.dto.ts +++ b/src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-update.dto.ts @@ -1,5 +1,5 @@ import { PartialType, OmitType } from "@nestjs/swagger"; -import { ShiftDto } from "./shift-create.dto"; +import { ShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-create.dto"; import { IsInt } from "class-validator"; export class UpdateShiftDto extends PartialType( diff --git a/src/time-and-attendance/modules/time-tracker/shifts/services/shifts-get.service.ts b/src/time-and-attendance/modules/time-tracker/shifts/services/shifts-get.service.ts index 8971cf8..c1c2e12 100644 --- a/src/time-and-attendance/modules/time-tracker/shifts/services/shifts-get.service.ts +++ b/src/time-and-attendance/modules/time-tracker/shifts/services/shifts-get.service.ts @@ -1,10 +1,11 @@ -import { toStringFromDate, toStringFromHHmm } from "../../../../utils/date-time.utils"; +import { toStringFromDate, toStringFromHHmm } from "src/time-and-attendance/utils/date-time.utils"; import { Injectable, NotFoundException } from "@nestjs/common"; import { PrismaService } from "src/prisma/prisma.service"; import { shift_select } from "src/time-and-attendance/utils/selects.utils"; -import { GetShiftDto } from "../dtos/shift-get.dto"; +import { GetShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-get.dto"; -/** + +/** * _____________________________________________________________________________________ * * @@ -15,6 +16,7 @@ import { GetShiftDto } from "../dtos/shift-get.dto"; * _____________________________________________________________________________________ */ + @Injectable() export class ShiftsGetService { constructor( diff --git a/src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service.ts b/src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service.ts index cca5e5a..e16797c 100644 --- a/src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service.ts +++ b/src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service.ts @@ -1,12 +1,12 @@ -import { CreateResult, NormedOk, NormedErr, UpdatePayload, UpdateResult, Normalized, UpdateChanges } from "src/time-and-attendance/utils/type.utils"; -import { overlaps, toDateFromString, toHHmmFromString, toStringFromDate, toStringFromHHmm } from "../../../../utils/date-time.utils"; -import { BadRequestException, ConflictException, Injectable, NotFoundException } from "@nestjs/common"; +import { CreateShiftResult, NormedOk, NormedErr, UpdateShiftResult, UpdateShiftPayload, UpdateShiftChanges, Normalized } from "src/time-and-attendance/utils/type.utils"; +import { overlaps, toStringFromHHmm, toStringFromDate, toDateFromString, toHHmmFromString } from "src/time-and-attendance/utils/date-time.utils"; +import { Injectable, BadRequestException, ConflictException, NotFoundException } from "@nestjs/common"; import { OvertimeService } from "src/time-and-attendance/domains/services/overtime.service"; import { UpdateShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-update.dto"; import { PrismaService } from "src/prisma/prisma.service"; import { shift_select } from "src/time-and-attendance/utils/selects.utils"; -import { GetShiftDto } from "../dtos/shift-get.dto"; -import { ShiftDto } from "../dtos/shift-create.dto"; +import { GetShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-get.dto"; +import { ShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-create.dto"; @@ -25,7 +25,7 @@ export class ShiftsUpsertService { //checks for overlaping shifts //create new shifts //calculate overtime - async createShifts(dtos: ShiftDto[]): Promise { + async createShifts(dtos: ShiftDto[]): Promise { if (!Array.isArray(dtos) || dtos.length === 0) return []; const normed_shift: Array = dtos.map((dto, index) => { @@ -66,14 +66,14 @@ export class ShiftsUpsertService { }); return dtos.map((_dto, key) => indices.includes(key) - ? ({ ok: false, error: err } as CreateResult) + ? ({ ok: false, error: err } as CreateShiftResult) : ({ ok: false, error: new BadRequestException('Batch aborted due to overlaps in another date group') }) ); } } } return this.prisma.$transaction(async (tx) => { - const results: CreateResult[] = Array.from({ length: dtos.length }, () => ({ ok: false, error: new Error('uninitialized') })); + const results: CreateShiftResult[] = Array.from({ length: dtos.length }, () => ({ ok: false, error: new Error('uninitialized') })); normed_shift.forEach((x, i) => { @@ -157,16 +157,16 @@ export class ShiftsUpsertService { // update shifts in DB // recalculate overtime after update // return an updated version to display - async updateShifts(dtos: UpdateShiftDto[]): Promise { + async updateShifts(dtos: UpdateShiftDto[]): Promise { if (!Array.isArray(dtos) || dtos.length === 0) return []; - const updates: UpdatePayload[] = dtos.map((item) => { + const updates: UpdateShiftPayload[] = dtos.map((item) => { const { id, ...rest } = item; if (!Number.isInteger(id)) { throw new BadRequestException('Update shift payload is missing a valid id'); } - const changes: UpdateChanges = {}; + const changes: UpdateShiftChanges = {}; if (rest.date !== undefined) changes.date = rest.date; if (rest.start_time !== undefined) changes.start_time = rest.start_time; if (rest.end_time !== undefined) changes.end_time = rest.end_time; @@ -189,12 +189,12 @@ export class ShiftsUpsertService { const existing = regroup_id.get(update.id); if (!existing) { return updates.map(exist => exist.id === update.id - ? ({ ok: false, id: update.id, error: new NotFoundException(`Shift with id: ${update.id} not found`) } as UpdateResult) + ? ({ ok: false, id: update.id, error: new NotFoundException(`Shift with id: ${update.id} not found`) } as UpdateShiftResult) : ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to missing shift') })); } if (existing.is_approved) { return updates.map(exist => exist.id === update.id - ? ({ ok: false, id: update.id, error: new BadRequestException('Approved shift cannot be updated') } as UpdateResult) + ? ({ ok: false, id: update.id, error: new BadRequestException('Approved shift cannot be updated') } as UpdateShiftResult) : ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to approved shift in update set') })); } } @@ -249,7 +249,7 @@ export class ShiftsUpsertService { message: 'New shift overlaps with existing shift(s)', conflicts: [{ start_time: toStringFromHHmm(conflict.start), end_time: toStringFromHHmm(conflict.end), type: 'UNKNOWN' }], }) - } as UpdateResult) + } as UpdateShiftResult) : ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to overlap in another update') }) ); } @@ -271,7 +271,7 @@ export class ShiftsUpsertService { } } - const results: UpdateResult[] = []; + const results: UpdateShiftResult[] = []; for (const planned of planned_updates) { const data: any = {}; const { dto } = planned.update; diff --git a/src/time-and-attendance/modules/time-tracker/shifts/shifts.module.ts b/src/time-and-attendance/modules/time-tracker/shifts/shifts.module.ts index 2669e7d..e031f31 100644 --- a/src/time-and-attendance/modules/time-tracker/shifts/shifts.module.ts +++ b/src/time-and-attendance/modules/time-tracker/shifts/shifts.module.ts @@ -1,7 +1,8 @@ + import { BusinessLogicsModule } from 'src/time-and-attendance/domains/business-logics.module'; -import { ShiftsUpsertService } from './services/shifts-upsert.service'; -import { ShiftsGetService } from './services/shifts-get.service'; -import { ShiftController } from './controllers/shift.controller'; +import { ShiftsUpsertService } from 'src/time-and-attendance/modules/time-tracker/shifts/services/shifts-upsert.service'; +import { ShiftsGetService } from 'src/time-and-attendance/modules/time-tracker/shifts/services/shifts-get.service'; +import { ShiftController } from 'src/time-and-attendance/modules/time-tracker/shifts/controllers/shift.controller'; import { Module } from '@nestjs/common'; @Module({ diff --git a/src/time-and-attendance/modules/time-tracker/timesheets/controllers/timesheet.controller.ts b/src/time-and-attendance/modules/time-tracker/timesheets/controllers/timesheet.controller.ts index 7eb7209..9ec6d6e 100644 --- a/src/time-and-attendance/modules/time-tracker/timesheets/controllers/timesheet.controller.ts +++ b/src/time-and-attendance/modules/time-tracker/timesheets/controllers/timesheet.controller.ts @@ -1,6 +1,6 @@ -import { EmailToIdResolver } from "src/time-and-attendance/modules/shared/utils/resolve-email-id.utils"; -import { GetTimesheetsOverviewService } from "../services/timesheet-get-overview.service"; +import { GetTimesheetsOverviewService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service"; import { BadRequestException, Controller, Get, Query} from "@nestjs/common"; +import { EmailToIdResolver } from "src/time-and-attendance/modules/shared/utils/resolve-email-id.utils"; @Controller('timesheets') export class TimesheetController { diff --git a/src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-approval.service.ts b/src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-approval.service.ts index c22d0dc..088b5b7 100644 --- a/src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-approval.service.ts +++ b/src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-approval.service.ts @@ -1,7 +1,7 @@ -import { Injectable } from "@nestjs/common"; -import { Prisma, Timesheets } from "@prisma/client"; import { BaseApprovalService } from "src/common/shared/base-approval.service"; +import { Prisma, Timesheets } from "@prisma/client"; import { PrismaService } from "src/prisma/prisma.service"; +import { Injectable } from "@nestjs/common"; @Injectable() export class TimesheetApprovalService extends BaseApprovalService{ diff --git a/src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service.ts b/src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service.ts index 24aa158..e89d684 100644 --- a/src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service.ts +++ b/src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service.ts @@ -1,8 +1,8 @@ -import { Injectable, NotFoundException } from "@nestjs/common"; -import { PrismaService } from "src/prisma/prisma.service"; -import { NUMBER_OF_TIMESHEETS_TO_RETURN } from "src/time-and-attendance/utils/constants.utils"; import { sevenDaysFrom, toStringFromDate, toHHmmFromDate, toDateFromString } from "src/time-and-attendance/utils/date-time.utils"; +import { NUMBER_OF_TIMESHEETS_TO_RETURN } from "src/time-and-attendance/utils/constants.utils"; +import { Injectable, NotFoundException } from "@nestjs/common"; import { TotalExpenses, TotalHours } from "src/time-and-attendance/utils/type.utils"; +import { PrismaService } from "src/prisma/prisma.service"; @Injectable() export class GetTimesheetsOverviewService { diff --git a/src/time-and-attendance/modules/time-tracker/timesheets/timesheets.module.ts b/src/time-and-attendance/modules/time-tracker/timesheets/timesheets.module.ts index d9375cf..595d660 100644 --- a/src/time-and-attendance/modules/time-tracker/timesheets/timesheets.module.ts +++ b/src/time-and-attendance/modules/time-tracker/timesheets/timesheets.module.ts @@ -1,7 +1,7 @@ -import { GetTimesheetsOverviewService } from './services/timesheet-get-overview.service'; -import { TimesheetArchiveService } from './services/timesheet-archive.service'; -import { TimesheetController } from './controllers/timesheet.controller'; -import { SharedModule } from '../../shared/shared.module'; +import { GetTimesheetsOverviewService } from 'src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service'; +import { TimesheetArchiveService } from 'src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-archive.service'; +import { TimesheetController } from 'src/time-and-attendance/modules/time-tracker/timesheets/controllers/timesheet.controller'; +import { SharedModule } from 'src/time-and-attendance/modules/shared/shared.module'; import { Module } from '@nestjs/common'; @Module({ diff --git a/src/time-and-attendance/time-and-attendance.module.ts b/src/time-and-attendance/time-and-attendance.module.ts index 31155e9..ff54d41 100644 --- a/src/time-and-attendance/time-and-attendance.module.ts +++ b/src/time-and-attendance/time-and-attendance.module.ts @@ -1,6 +1,6 @@ -import { SchedulePresetsCommandService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-command.service"; +import { SchedulePresetsUpsertService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-upsert.service"; import { GetTimesheetsOverviewService } from "src/time-and-attendance/modules/time-tracker/timesheets/services/timesheet-get-overview.service"; -import { SchedulePresetsQueryService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-query.service"; +import { SchedulePresetsGetService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-get.service"; import { SchedulePresetsApplyService } from "src/time-and-attendance/modules/time-tracker/schedule-presets/services/schedule-presets-apply.service"; import { SchedulePresetsController } from "src/time-and-attendance/modules/time-tracker/schedule-presets/controller/schedule-presets.controller"; import { BusinessLogicsModule } from "src/time-and-attendance/domains/business-logics.module"; @@ -31,8 +31,8 @@ import { Module } from "@nestjs/common"; ShiftsGetService, ShiftsUpsertService, ExpenseUpsertService, - SchedulePresetsCommandService, - SchedulePresetsQueryService, + SchedulePresetsUpsertService, + SchedulePresetsGetService, SchedulePresetsApplyService, ], exports: [], diff --git a/src/time-and-attendance/utils/constants.utils.ts b/src/time-and-attendance/utils/constants.utils.ts index c02df87..e2f20fc 100644 --- a/src/time-and-attendance/utils/constants.utils.ts +++ b/src/time-and-attendance/utils/constants.utils.ts @@ -2,7 +2,7 @@ export const NUMBER_OF_TIMESHEETS_TO_RETURN = 2; export const DAILY_LIMIT_HOURS = 8; export const WEEKLY_LIMIT_HOURS = 40; export const PAY_PERIOD_ANCHOR = 2023-12-17; -export const ANCHOR_ISO = '2023-12-17'; // ancre date +export const ANCHOR_ISO = '2023-12-17'; export const PERIOD_DAYS = 14; export const PERIODS_PER_YEAR = 26; export const MS_PER_DAY = 86_400_000; diff --git a/src/time-and-attendance/utils/type.utils.ts b/src/time-and-attendance/utils/type.utils.ts index 0903b87..0264f3f 100644 --- a/src/time-and-attendance/utils/type.utils.ts +++ b/src/time-and-attendance/utils/type.utils.ts @@ -4,6 +4,9 @@ import { UpdateShiftDto } from "src/time-and-attendance/modules/time-tracker/shi import { GetShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-get.dto"; import { ShiftDto } from "src/time-and-attendance/modules/time-tracker/shifts/dtos/shift-create.dto"; import { Prisma } from "@prisma/client"; +import { SchedulePresetsDto } from "src/time-and-attendance/modules/time-tracker/schedule-presets/dtos/create-schedule-presets.dto"; +import { GetExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-get.dto"; +import { updateExpenseDto } from "src/time-and-attendance/modules/expenses/dtos/expense-update.dto"; export type TotalHours = { regular: number; @@ -29,11 +32,24 @@ export type ShiftWithOvertimeDto = { overtime: WeekOvertimeSummary; }; -export type CreateResult = { ok: true; data: ShiftWithOvertimeDto } | { ok: false; error: any }; -export type UpdateChanges = Omit; -export type UpdatePayload = { id: number; dto: UpdateChanges }; -export type UpdateResult = { ok: true; id: number; data: ShiftWithOvertimeDto } | { ok: false; id: number; error: any }; -export type DeleteResult = { ok: true; id: number; overtime: WeekOvertimeSummary } | { ok: false; id: number; error: any }; +export type CreateShiftResult = { ok: true; data: ShiftWithOvertimeDto } | { ok: false; error: any }; +export type UpdateShiftChanges = Omit; +export type UpdateShiftPayload = { id: number; dto: UpdateShiftChanges }; +export type UpdateShiftResult = { ok: true; id: number; data: ShiftWithOvertimeDto } | { ok: false; id: number; error: any }; +export type DeleteShiftResult = { ok: true; id: number; overtime: WeekOvertimeSummary } | { ok: false; id: number; error: any }; + +export type DeletePresetResult = { ok: true; id: number; } | { ok: false; id: number; error: any }; +export type CreatePresetResult = { ok: true; } | { ok: false; error: any }; +export type UpdatePresetResult = { ok: true; id: number; data: SchedulePresetsDto } | { ok: false; id: number; error: any }; + +export type NormalizedExpense = { date: Date; comment: string; supervisor_comment?: string; }; + +export type CreateExpenseResult = { ok: true; data: GetExpenseDto } | { ok: false; error: any }; +export type UpdateExpensePayload = { id: number; dto: updateExpenseDto }; +export type UpdateExpenseResult = { ok: true; id: number; data: GetExpenseDto } | { ok: false; id: number; error: any }; +export type DeleteExpenseResult = { ok: true; id: number; } | { ok: false; id: number; error: any }; + + export type NormedOk = { index: number; dto: ShiftDto; normed: Normalized }; export type NormedErr = { index: number; error: any };