fix(shifts): removed unused overtime calculation and return from create or update shifts
This commit is contained in:
parent
7817c3b758
commit
efc06b8857
|
|
@ -4,7 +4,6 @@ import { Injectable, BadRequestException, ConflictException, NotFoundException }
|
||||||
import { shift_select, timesheet_select } from "src/time-and-attendance/utils/selects.utils";
|
import { shift_select, timesheet_select } from "src/time-and-attendance/utils/selects.utils";
|
||||||
import { BankCodesResolver } from "src/time-and-attendance/utils/resolve-bank-type-id.utils";
|
import { BankCodesResolver } from "src/time-and-attendance/utils/resolve-bank-type-id.utils";
|
||||||
import { EmailToIdResolver } from "src/time-and-attendance/utils/resolve-email-id.utils";
|
import { EmailToIdResolver } from "src/time-and-attendance/utils/resolve-email-id.utils";
|
||||||
import { OvertimeService } from "src/time-and-attendance/domains/services/overtime.service";
|
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
import { GetShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-get.dto";
|
import { GetShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-get.dto";
|
||||||
import { ShiftEntity } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-payload.dto";
|
import { ShiftEntity } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-payload.dto";
|
||||||
|
|
@ -15,7 +14,6 @@ import { response } from "express";
|
||||||
export class ShiftsUpsertService {
|
export class ShiftsUpsertService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly overtime: OvertimeService,
|
|
||||||
private readonly emailResolver: EmailToIdResolver,
|
private readonly emailResolver: EmailToIdResolver,
|
||||||
private readonly typeResolver: BankCodesResolver,
|
private readonly typeResolver: BankCodesResolver,
|
||||||
) { }
|
) { }
|
||||||
|
|
@ -27,7 +25,6 @@ export class ShiftsUpsertService {
|
||||||
//loads all shifts from a selected day to check for overlaping shifts
|
//loads all shifts from a selected day to check for overlaping shifts
|
||||||
//checks for overlaping shifts
|
//checks for overlaping shifts
|
||||||
//create new shifts
|
//create new shifts
|
||||||
//calculate overtime
|
|
||||||
async createShifts(email: string, dtos: ShiftDto[]): Promise<CreateShiftResult[]> {
|
async createShifts(email: string, dtos: ShiftDto[]): Promise<CreateShiftResult[]> {
|
||||||
if (!Array.isArray(dtos) || dtos.length === 0) return [];
|
if (!Array.isArray(dtos) || dtos.length === 0) return [];
|
||||||
|
|
||||||
|
|
@ -217,7 +214,6 @@ export class ShiftsUpsertService {
|
||||||
|
|
||||||
|
|
||||||
const { type: bank_type } = await this.typeResolver.findTypeByBankCodeId(row.bank_code_id);
|
const { type: bank_type } = await this.typeResolver.findTypeByBankCodeId(row.bank_code_id);
|
||||||
const summary = await this.overtime.getWeekOvertimeSummary(timesheet_id, normed.date, tx);
|
|
||||||
|
|
||||||
const shift: GetShiftDto = {
|
const shift: GetShiftDto = {
|
||||||
shift_id: row.id,
|
shift_id: row.id,
|
||||||
|
|
@ -230,7 +226,7 @@ export class ShiftsUpsertService {
|
||||||
is_approved: false,
|
is_approved: false,
|
||||||
comment: row.comment ?? undefined,
|
comment: row.comment ?? undefined,
|
||||||
};
|
};
|
||||||
results[index] = { ok: true, data: { shift, overtime: summary } };
|
results[index] = { ok: true, data: { shift } };
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|
@ -247,7 +243,6 @@ export class ShiftsUpsertService {
|
||||||
// check for overlaping possibility
|
// check for overlaping possibility
|
||||||
// buil a set of data to manipulate modified data only
|
// buil a set of data to manipulate modified data only
|
||||||
// update shifts in DB
|
// update shifts in DB
|
||||||
// recalculate overtime after update
|
|
||||||
// return an updated version to display
|
// return an updated version to display
|
||||||
async updateShifts(dtos: ShiftDto[]): Promise<UpdateShiftResult[]> {
|
async updateShifts(dtos: ShiftDto[]): Promise<UpdateShiftResult[]> {
|
||||||
if (!Array.isArray(dtos) || dtos.length === 0) throw new BadRequestException({ error_code: 'SHIFT_MISSING' });
|
if (!Array.isArray(dtos) || dtos.length === 0) throw new BadRequestException({ error_code: 'SHIFT_MISSING' });
|
||||||
|
|
@ -414,10 +409,6 @@ export class ShiftsUpsertService {
|
||||||
data,
|
data,
|
||||||
select: shift_select,
|
select: shift_select,
|
||||||
});
|
});
|
||||||
const summary_new = await this.overtime.getWeekOvertimeSummary(row.timesheet_id, planned.exist_shift.date, tx);
|
|
||||||
if (row.date.getTime() !== planned.exist_shift.date.getTime()) {
|
|
||||||
await this.overtime.getWeekOvertimeSummary(row.timesheet_id, row.date, tx);
|
|
||||||
}
|
|
||||||
|
|
||||||
const type = await this.typeResolver.findTypeByBankCodeId(row.bank_code_id);
|
const type = await this.typeResolver.findTypeByBankCodeId(row.bank_code_id);
|
||||||
|
|
||||||
|
|
@ -433,7 +424,7 @@ export class ShiftsUpsertService {
|
||||||
comment: row.comment ?? undefined,
|
comment: row.comment ?? undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
results.push({ ok: true, id: planned.exist_shift.id, data: { shift: dto, overtime: summary_new } });
|
results.push({ ok: true, id: planned.exist_shift.id, data: { shift: dto } });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new BadRequestException('INVALID_SHIFT');
|
throw new BadRequestException('INVALID_SHIFT');
|
||||||
}
|
}
|
||||||
|
|
@ -446,7 +437,6 @@ export class ShiftsUpsertService {
|
||||||
// DELETE
|
// DELETE
|
||||||
//_________________________________________________________________
|
//_________________________________________________________________
|
||||||
//finds shifts using shit_ids
|
//finds shifts using shit_ids
|
||||||
//recalc overtime shifts after delete
|
|
||||||
//blocs deletion if approved
|
//blocs deletion if approved
|
||||||
async deleteShift(shift_id: number) {
|
async deleteShift(shift_id: number) {
|
||||||
return await this.prisma.$transaction(async (tx) => {
|
return await this.prisma.$transaction(async (tx) => {
|
||||||
|
|
@ -457,12 +447,7 @@ export class ShiftsUpsertService {
|
||||||
if (!shift) throw new ConflictException({ error_code: 'SHIFT_INVALID' });
|
if (!shift) throw new ConflictException({ error_code: 'SHIFT_INVALID' });
|
||||||
|
|
||||||
await tx.shifts.delete({ where: { id: shift_id } });
|
await tx.shifts.delete({ where: { id: shift_id } });
|
||||||
|
return { success: true };
|
||||||
const summary = await this.overtime.getWeekOvertimeSummary(shift.timesheet_id, shift.date, tx);
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
overtime: summary
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ export type Normalized = { date: Date; start_time: Date; end_time: Date; bank_co
|
||||||
|
|
||||||
export type ShiftWithOvertimeDto = {
|
export type ShiftWithOvertimeDto = {
|
||||||
shift: GetShiftDto;
|
shift: GetShiftDto;
|
||||||
overtime: WeekOvertimeSummary;
|
// overtime: WeekOvertimeSummary;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CreateShiftResult = { ok: true; data: ShiftWithOvertimeDto } | { ok: false; error: any };
|
export type CreateShiftResult = { ok: true; data: ShiftWithOvertimeDto } | { ok: false; error: any };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user