diff --git a/docs/swagger/swagger-spec.json b/docs/swagger/swagger-spec.json index 0cf1209..07055ed 100644 --- a/docs/swagger/swagger-spec.json +++ b/docs/swagger/swagger-spec.json @@ -448,6 +448,14 @@ "schema": { "type": "string" } + }, + { + "name": "action", + "required": true, + "in": "query", + "schema": { + "type": "string" + } } ], "requestBody": { diff --git a/src/modules/shifts/controllers/shifts.controller.ts b/src/modules/shifts/controllers/shifts.controller.ts index ba6dead..c8b7bbf 100644 --- a/src/modules/shifts/controllers/shifts.controller.ts +++ b/src/modules/shifts/controllers/shifts.controller.ts @@ -22,7 +22,8 @@ export class ShiftsController { @Put('upsert/:email') async upsert_by_date( @Param('email') email_param: string, - @Body() payload: UpsertShiftDto, action: UpsertAction, + @Query('action') action: UpsertAction, + @Body() payload: UpsertShiftDto, ) { return this.shiftsCommandService.upsertShifts(email_param, action, payload); } diff --git a/src/modules/shifts/dtos/create-shift.dto.ts b/src/modules/shifts/dtos/create-shift.dto.ts deleted file mode 100644 index 0fa93ab..0000000 --- a/src/modules/shifts/dtos/create-shift.dto.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { Type } from "class-transformer"; -import { Allow, IsDateString, IsInt, IsString } from "class-validator"; - -export class CreateShiftDto { - @ApiProperty({ - example: 1, - description: 'Unique ID of the shift (auto-generated)', - }) - @Allow() - id: number; - - @ApiProperty({ - example: 101, - description: 'ID number for a set timesheet', - }) - @Type(() => Number) - @IsInt() - timesheet_id: number; - - @ApiProperty({ - example: 7, - description: 'ID number of a shift code (link with bank-codes)', - }) - @Type(() => Number) - @IsInt() - bank_code_id: number; - - @ApiProperty({ - example: '3018-10-20T00:00:00.000Z', - description: 'Date where the shift takes place', - }) - @IsDateString() - date: string; - - @ApiProperty({ - example: '3018-10-20T08:00:00.000Z', - description: 'Start time of the said shift', - }) - @IsDateString() - start_time: string; - - @ApiProperty({ - example: '3018-10-20T17:00:00.000Z', - description: 'End time of the said shift', - }) - @IsDateString() - end_time: string; - - @IsString() - comment: string; -} diff --git a/src/modules/shifts/dtos/search-shift.dto.ts b/src/modules/shifts/dtos/search-shift.dto.ts deleted file mode 100644 index 233a9b6..0000000 --- a/src/modules/shifts/dtos/search-shift.dto.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Type } from "class-transformer"; -import { IsDateString, IsInt, IsOptional, IsString } from "class-validator"; - -export class SearchShiftsDto { - @IsOptional() - @Type(()=> Number) - @IsInt() - employee_id?: number; - - @IsOptional() - @Type(()=> Number) - @IsInt() - bank_code_id?: number; - - @IsOptional() - @IsString() - comment_contains?: string; - - @IsOptional() - @IsDateString() - start_date?: string; - - @IsOptional() - @IsDateString() - end_date?: string; - - @IsOptional() - @Type(()=> Number) - @IsInt() - timesheet_id?: number; - - -} \ No newline at end of file diff --git a/src/modules/shifts/dtos/update-shift.dto.ts b/src/modules/shifts/dtos/update-shift.dto.ts deleted file mode 100644 index 53f033f..0000000 --- a/src/modules/shifts/dtos/update-shift.dto.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { PartialType } from "@nestjs/swagger"; -import { CreateShiftDto } from "./create-shift.dto"; - -export class UpdateShiftsDto extends PartialType(CreateShiftDto){} \ No newline at end of file diff --git a/src/modules/shifts/services/shifts-command.service.ts b/src/modules/shifts/services/shifts-command.service.ts index fff2d91..a54f9e9 100644 --- a/src/modules/shifts/services/shifts-command.service.ts +++ b/src/modules/shifts/services/shifts-command.service.ts @@ -1,5 +1,4 @@ import { BadRequestException, Injectable, Logger, NotFoundException } from "@nestjs/common"; -import { normalizeShiftPayload } from "../utils/shifts.utils"; import { DayShiftResponse } from "../types-and-interfaces/shifts-upsert.types"; import { EmailToIdResolver } from "src/modules/shared/utils/resolve-email-id.utils"; import { Prisma, Shifts } from "@prisma/client"; diff --git a/src/modules/shifts/services/shifts-query.service.ts b/src/modules/shifts/services/shifts-query.service.ts index bfe3fe8..68006df 100644 --- a/src/modules/shifts/services/shifts-query.service.ts +++ b/src/modules/shifts/services/shifts-query.service.ts @@ -111,95 +111,4 @@ export class ShiftsQueryService { //return by default the list of employee in ascending alphabetical order return Array.from(mapRow.values()).sort((a,b) => a.full_name.localeCompare(b.full_name)); } - - //_____________________________________________________________________________________________ - // Deprecated or unused methods - //_____________________________________________________________________________________________ - - // async update(id: number, dto: UpdateShiftsDto): Promise { - // await this.findOne(id); - // const { timesheet_id, bank_code_id, date,start_time,end_time, comment} = dto; - // return this.prisma.shifts.update({ - // where: { id }, - // data: { - // ...(timesheet_id !== undefined && { timesheet_id }), - // ...(bank_code_id !== undefined && { bank_code_id }), - // ...(date !== undefined && { date }), - // ...(start_time !== undefined && { start_time }), - // ...(end_time !== undefined && { end_time }), - // ...(comment !== undefined && { comment }), - // }, - // include: { timesheet: { include: { employee: { include: { user: true } } } }, - // bank_code: true, - // }, - // }); - // } - - // async remove(id: number): Promise { - // await this.findOne(id); - // return this.prisma.shifts.delete({ where: { id } }); - // } - - // async create(dto: CreateShiftDto): Promise { -// const { timesheet_id, bank_code_id, date, start_time, end_time, comment } = dto; - -// //shift creation -// const shift = await this.prisma.shifts.create({ -// data: { timesheet_id, bank_code_id, date, start_time, end_time, comment }, -// include: { timesheet: { include: { employee: { include: { user: true } } } }, -// bank_code: true, -// }, -// }); - -// //fetches all shifts of the same day to check for daily overtime -// const same_day_shifts = await this.prisma.shifts.findMany({ -// where: { timesheet_id, date }, -// select: { id: true, date: true, start_time: true, end_time: true }, -// }); - -// //sums hours of the day -// const total_hours = same_day_shifts.reduce((sum, s) => { -// return sum + hoursBetweenSameDay(s.date, s.start_time, s.end_time); -// }, 0 ); - -// //Notify if total hours > 8 for a single day -// if(total_hours > DAILY_LIMIT_HOURS ) { -// const user_id = String(shift.timesheet.employee.user.id); -// const date_label = new Date(date).toLocaleDateString('fr-CA'); -// this.notifs.notify(user_id, { -// type: 'shift.overtime.daily', -// severity: 'warn', -// message: `Tu viens de dépasser ${DAILY_LIMIT_HOURS.toFixed(2)}h pour la journée du ${date_label} -// (total: ${total_hours.toFixed(2)}h).`, -// ts: new Date().toISOString(), -// meta: { -// timesheet_id, -// date: new Date(date).toISOString(), -// total_hours, -// threshold: DAILY_LIMIT_HOURS, -// last_shift_id: shift.id -// }, -// }); -// } -// return shift; -// } -// async findAll(filters: SearchShiftsDto): Promise { -// const where = buildPrismaWhere(filters); -// const shifts = await this.prisma.shifts.findMany({ where }) -// return shifts; -// } - -// async findOne(id: number): Promise { -// const shift = await this.prisma.shifts.findUnique({ -// where: { id }, -// include: { timesheet: { include: { employee: { include: { user: true } } } }, -// bank_code: true, -// }, -// }); -// if(!shift) { -// throw new NotFoundException(`Shift #${id} not found`); -// } -// return shift; -// } - } \ No newline at end of file diff --git a/src/modules/shifts/utils/shifts.utils.ts b/src/modules/shifts/utils/shifts.utils.ts index a0fb13e..b2bd6e8 100644 --- a/src/modules/shifts/utils/shifts.utils.ts +++ b/src/modules/shifts/utils/shifts.utils.ts @@ -1,6 +1,4 @@ import { NotFoundException } from "@nestjs/common"; -import { ShiftPayloadDto } from "../dtos/upsert-shift.dto"; -import { timeFromHHMM } from "../helpers/shifts-date-time-helpers"; export function overlaps( a_start_ms: number,