fix(shifts): modified controller to accept a query action. clean up module
This commit is contained in:
parent
5292f1af11
commit
d95b6471cd
|
|
@ -448,6 +448,14 @@
|
|||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "action",
|
||||
"required": true,
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
import { PartialType } from "@nestjs/swagger";
|
||||
import { CreateShiftDto } from "./create-shift.dto";
|
||||
|
||||
export class UpdateShiftsDto extends PartialType(CreateShiftDto){}
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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<Shifts> {
|
||||
// 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<Shifts> {
|
||||
// await this.findOne(id);
|
||||
// return this.prisma.shifts.delete({ where: { id } });
|
||||
// }
|
||||
|
||||
// async create(dto: CreateShiftDto): Promise<Shifts> {
|
||||
// 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 <Shifts[]> {
|
||||
// const where = buildPrismaWhere(filters);
|
||||
// const shifts = await this.prisma.shifts.findMany({ where })
|
||||
// return shifts;
|
||||
// }
|
||||
|
||||
// async findOne(id: number): Promise<Shifts> {
|
||||
// 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;
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user