clean(shifts): cleaning
This commit is contained in:
parent
c2203f77cb
commit
457757a066
|
|
@ -52,7 +52,7 @@ export class ShiftsUpsertService {
|
||||||
select: timesheet_select,
|
select: timesheet_select,
|
||||||
});
|
});
|
||||||
if (!timesheet) {
|
if (!timesheet) {
|
||||||
return { index, error: new NotFoundException(`Timesheet not found`)};
|
return { index, error: new NotFoundException(`Timesheet not found`) };
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -136,7 +136,7 @@ export class ShiftsUpsertService {
|
||||||
const day_date = new Date(day);
|
const day_date = new Date(day);
|
||||||
const rows = await tx.shifts.findMany({
|
const rows = await tx.shifts.findMany({
|
||||||
where: { timesheet_id, date: day_date },
|
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(
|
existing_map.set(
|
||||||
key,
|
key,
|
||||||
|
|
@ -153,7 +153,7 @@ export class ShiftsUpsertService {
|
||||||
const day_key = new Date(normed.date.getFullYear(), normed.date.getMonth(), normed.date.getDate()).getTime();
|
const day_key = new Date(normed.date.getFullYear(), normed.date.getMonth(), normed.date.getDate()).getTime();
|
||||||
const map_key = `${timesheet_id}|${day_key}`;
|
const map_key = `${timesheet_id}|${day_key}`;
|
||||||
let existing = existing_map.get(map_key);
|
let existing = existing_map.get(map_key);
|
||||||
if(!existing) {
|
if (!existing) {
|
||||||
existing = [];
|
existing = [];
|
||||||
existing_map.set(map_key, existing);
|
existing_map.set(map_key, existing);
|
||||||
}
|
}
|
||||||
|
|
@ -189,8 +189,7 @@ export class ShiftsUpsertService {
|
||||||
|
|
||||||
const normalizeHHmm = (value: Date) => toHHmmFromString(toStringFromHHmm(value));
|
const normalizeHHmm = (value: Date) => toHHmmFromString(toStringFromHHmm(value));
|
||||||
|
|
||||||
for (const { timesheet_id, day, key } of timesheet_keys) {
|
for (const { key } of timesheet_keys) {
|
||||||
const day_date = new Date(day);
|
|
||||||
existing.push({
|
existing.push({
|
||||||
start_time: normalizeHHmm(row.start_time),
|
start_time: normalizeHHmm(row.start_time),
|
||||||
end_time: normalizeHHmm(row.end_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 summary = await this.overtime.getWeekOvertimeSummary(timesheet_id, normed.date, tx);
|
||||||
|
|
||||||
const shift: GetShiftDto = {
|
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 exist_shift = regroup_id.get(update.id)!;
|
||||||
const date_string = update.dto.date ?? toStringFromDate(exist_shift.date);
|
const date_string = update.dto.date ?? toStringFromDate(exist_shift.date);
|
||||||
const start_string = update.dto.start_time ?? toStringFromHHmm(exist_shift.start_time);
|
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) {
|
for (const planned of planned_updates) {
|
||||||
const data: any = {};
|
const data: any = {};
|
||||||
const { dto } = planned.update;
|
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.start_time !== undefined) data.start_time = planned.normed.start_time;
|
||||||
if (dto.end_time !== undefined) data.end_time = planned.normed.end_time;
|
if (dto.end_time !== undefined) data.end_time = planned.normed.end_time;
|
||||||
if (dto.type !== undefined) data.type = dto.type;
|
if (dto.type !== undefined) data.type = dto.type;
|
||||||
if (dto.is_remote !== undefined) data.is_remote = dto.is_remote;
|
if (dto.is_remote !== undefined) data.is_remote = dto.is_remote;
|
||||||
if (dto.comment !== undefined) data.comment = dto.comment ?? null;
|
if (dto.comment !== undefined) data.comment = dto.comment ?? null;
|
||||||
|
|
||||||
const row = await tx.shifts.update({
|
const row = await tx.shifts.update({
|
||||||
where: { id: planned.exist_shift.id },
|
where: { id: planned.exist_shift.id },
|
||||||
|
|
@ -421,7 +419,7 @@ export class ShiftsUpsertService {
|
||||||
//_________________________________________________________________
|
//_________________________________________________________________
|
||||||
//converts all string hours and date to Date and HHmm formats
|
//converts all string hours and date to Date and HHmm formats
|
||||||
private normalizeShiftDto = async (dto: ShiftDto): Promise<Normalized> => {
|
private normalizeShiftDto = async (dto: ShiftDto): Promise<Normalized> => {
|
||||||
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 date = toDateFromString(dto.date);
|
||||||
const start_time = toHHmmFromString(dto.start_time);
|
const start_time = toHHmmFromString(dto.start_time);
|
||||||
const end_time = toHHmmFromString(dto.end_time);
|
const end_time = toHHmmFromString(dto.end_time);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user