fix(shift): changed default value of is_approved in asLocalDateOn

This commit is contained in:
Matthieu Haineault 2025-10-14 11:14:43 -04:00
parent 8ad8076f4d
commit 1fe2c1291c
3 changed files with 13 additions and 13 deletions

View File

@ -49,9 +49,9 @@ export class ShiftsHelpersService {
return id; return id;
} }
async getDayShifts(tx: Tx, timesheet_id: number, dateIso: string) { async getDayShifts(tx: Tx, timesheet_id: number, date_only: Date) {
return tx.shifts.findMany({ return tx.shifts.findMany({
where: { timesheet_id, date: dateIso }, where: { timesheet_id, date: date_only },
include: { bank_code: true }, include: { bank_code: true },
orderBy: { start_time: 'asc' }, orderBy: { start_time: 'asc' },
}); });

View File

@ -89,7 +89,7 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
const new_norm_shift = await this.helpersService.normalizeRequired(dto.new_shift); const new_norm_shift = await this.helpersService.normalizeRequired(dto.new_shift);
const new_bank_code_id = await this.helpersService.resolveBankIdRequired(tx, new_norm_shift.type, 'new_shift'); const new_bank_code_id = await this.helpersService.resolveBankIdRequired(tx, new_norm_shift.type, 'new_shift');
const day_shifts = await this.helpersService.getDayShifts(tx, timesheet_id, date_iso); const day_shifts = await this.helpersService.getDayShifts(tx, timesheet_id, date_only);
await this.helpersService.assertNoOverlap(day_shifts, new_norm_shift); await this.helpersService.assertNoOverlap(day_shifts, new_norm_shift);
@ -106,7 +106,7 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
}, },
}); });
await this.helpersService.afterWriteOvertimeAndLog(tx, employee_id, date_only,'create'); await this.helpersService.afterWriteOvertimeAndLog(tx, employee_id, date_only,'create');
const fresh_shift = await this.helpersService.getDayShifts(tx, timesheet_id, date_iso); const fresh_shift = await this.helpersService.getDayShifts(tx, timesheet_id, date_only);
return { action: 'create', day: await this.helpersService.mapDay(fresh_shift)}; return { action: 'create', day: await this.helpersService.mapDay(fresh_shift)};
}); });
} }
@ -129,7 +129,7 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
const old_bank_code_id = await this.helpersService.resolveBankIdRequired(tx, old_norm_shift.type, 'old_shift'); const old_bank_code_id = await this.helpersService.resolveBankIdRequired(tx, old_norm_shift.type, 'old_shift');
const new_bank_code_id = await this.helpersService.resolveBankIdRequired(tx, new_norm_shift.type, 'new_shift'); const new_bank_code_id = await this.helpersService.resolveBankIdRequired(tx, new_norm_shift.type, 'new_shift');
const day_shifts = await this.helpersService.getDayShifts(tx, timesheet_id, date_iso); const day_shifts = await this.helpersService.getDayShifts(tx, timesheet_id, date_only);
const existing = await this.helpersService.findExactOldShift(tx, { const existing = await this.helpersService.findExactOldShift(tx, {
timesheet_id, timesheet_id,
date_only, date_only,
@ -151,7 +151,7 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
}, },
}); });
await this.helpersService.afterWriteOvertimeAndLog(tx, employee_id, date_only, 'update'); await this.helpersService.afterWriteOvertimeAndLog(tx, employee_id, date_only, 'update');
const fresh_shift = await this.helpersService.getDayShifts(tx, timesheet_id, date_iso); const fresh_shift = await this.helpersService.getDayShifts(tx, timesheet_id, date_only);
return { action: 'update', day: await this.helpersService.mapDay(fresh_shift)}; return { action: 'update', day: await this.helpersService.mapDay(fresh_shift)};
}); });
@ -168,23 +168,23 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
return this.prisma.$transaction(async (tx) => { return this.prisma.$transaction(async (tx) => {
const date_only = toDateOnly(date_iso); const date_only = toDateOnly(date_iso);
const employee_id = await this.emailResolver.findIdByEmail(email); const employee_id = await this.emailResolver.findIdByEmail(email);
const { id: timesheet_id } = await this.helpersService.ensureTimesheet(tx, employee_id, date_only);
const old_norm_shift = await this.helpersService.normalizeRequired(dto.old_shift, 'old_shift'); const { id: timesheet_id } = await this.helpersService.ensureTimesheet(tx, employee_id, date_only);
const old_bank_code_id = await this.typeResolver.findByType(old_norm_shift.type); const norm_shift = await this.helpersService.normalizeRequired(dto.old_shift, 'old_shift');
const bank_code_id = await this.typeResolver.findByType(norm_shift.type);
const existing = await this.helpersService.findExactOldShift(tx, { const existing = await this.helpersService.findExactOldShift(tx, {
timesheet_id, timesheet_id,
date_only, date_only,
norm: old_norm_shift, norm: norm_shift,
bank_code_id: old_bank_code_id.id, bank_code_id: bank_code_id.id,
}); });
if(!existing) throw new NotFoundException('[SHIFT_STALE]- The shift was modified or deleted by someone else'); if(!existing) throw new NotFoundException('[SHIFT_STALE]- The shift was modified or deleted by someone else');
await tx.shifts.delete({ where: { id: existing.id } }); await tx.shifts.delete({ where: { id: existing.id } });
await this.helpersService.afterWriteOvertimeAndLog(tx, employee_id, date_only, 'delete'); await this.helpersService.afterWriteOvertimeAndLog(tx, employee_id, date_only, 'delete');
const fresh_shift = await this.helpersService.getDayShifts(tx, timesheet_id, date_iso); const fresh_shift = await this.helpersService.getDayShifts(tx, timesheet_id, date_only);
return { day: await this.helpersService.mapDay(fresh_shift)}; return { day: await this.helpersService.mapDay(fresh_shift)};
}); });
} }

View File

@ -49,7 +49,7 @@ export function normalizeShiftPayload(payload: {
const type = (payload.type || '').trim().toUpperCase(); const type = (payload.type || '').trim().toUpperCase();
const is_remote = payload.is_remote === true; const is_remote = payload.is_remote === true;
const is_approved = payload.is_approved === false; const is_approved = payload.is_approved;
//normalize comment //normalize comment
const trimmed = typeof payload.comment === 'string' ? payload.comment.trim() : null; const trimmed = typeof payload.comment === 'string' ? payload.comment.trim() : null;
const comment = trimmed && trimmed.length > 0 ? trimmed : null; const comment = trimmed && trimmed.length > 0 ? trimmed : null;