diff --git a/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts b/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts index 52884c7..46e89b9 100644 --- a/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts +++ b/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts @@ -52,7 +52,7 @@ export class ShiftsUpsertService { select: timesheet_select, }); if (!timesheet) { - return { index, error: new NotFoundException(`Timesheet not found`)}; + return { index, error: new NotFoundException(`Timesheet not found`) }; } return { @@ -136,7 +136,7 @@ export class ShiftsUpsertService { const day_date = new Date(day); const rows = await tx.shifts.findMany({ where: { timesheet_id, date: day_date }, - select: { start_time: true, end_time: true }, + select: { start_time: true, end_time: true, id: true }, }); existing_map.set( key, @@ -153,7 +153,7 @@ export class ShiftsUpsertService { const day_key = new Date(normed.date.getFullYear(), normed.date.getMonth(), normed.date.getDate()).getTime(); const map_key = `${timesheet_id}|${day_key}`; let existing = existing_map.get(map_key); - if(!existing) { + if (!existing) { existing = []; existing_map.set(map_key, existing); } @@ -189,14 +189,13 @@ export class ShiftsUpsertService { const normalizeHHmm = (value: Date) => toHHmmFromString(toStringFromHHmm(value)); - for (const { timesheet_id, day, key } of timesheet_keys) { - const day_date = new Date(day); - existing.push({ - start_time: normalizeHHmm(row.start_time), - end_time: normalizeHHmm(row.end_time) + for (const { key } of timesheet_keys) { + existing.push({ + start_time: normalizeHHmm(row.start_time), + end_time: normalizeHHmm(row.end_time) }); existing_map.set( - key, + key, existing.map(row => ({ start_time: normalizeHHmm(row.start_time), end_time: normalizeHHmm(row.end_time), @@ -204,8 +203,7 @@ 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 = { @@ -279,7 +277,7 @@ export class ShiftsUpsertService { } } - const planned_updates = updates.map( update => { + const planned_updates = updates.map(update => { const exist_shift = regroup_id.get(update.id)!; const date_string = update.dto.date ?? toStringFromDate(exist_shift.date); const start_string = update.dto.start_time ?? toStringFromHHmm(exist_shift.start_time); @@ -356,12 +354,12 @@ export class ShiftsUpsertService { for (const planned of planned_updates) { const data: any = {}; const { dto } = planned.update; - if (dto.date !== undefined) data.date = planned.normed.date; + if (dto.date !== undefined) data.date = planned.normed.date; if (dto.start_time !== undefined) data.start_time = planned.normed.start_time; - if (dto.end_time !== undefined) data.end_time = planned.normed.end_time; - if (dto.type !== undefined) data.type = dto.type; - if (dto.is_remote !== undefined) data.is_remote = dto.is_remote; - if (dto.comment !== undefined) data.comment = dto.comment ?? null; + if (dto.end_time !== undefined) data.end_time = planned.normed.end_time; + if (dto.type !== undefined) data.type = dto.type; + if (dto.is_remote !== undefined) data.is_remote = dto.is_remote; + if (dto.comment !== undefined) data.comment = dto.comment ?? null; const row = await tx.shifts.update({ where: { id: planned.exist_shift.id }, @@ -421,7 +419,7 @@ export class ShiftsUpsertService { //_________________________________________________________________ //converts all string hours and date to Date and HHmm formats private normalizeShiftDto = async (dto: ShiftDto): Promise => { - const { id: bank_code_id} = await this.typeResolver.findBankCodeIDByType(dto.type); + const { id: bank_code_id } = await this.typeResolver.findBankCodeIDByType(dto.type); const date = toDateFromString(dto.date); const start_time = toHHmmFromString(dto.start_time); const end_time = toHHmmFromString(dto.end_time);