refactor(shifts): change structure of error management returns
This commit is contained in:
parent
407f04ac0b
commit
be00798961
|
|
@ -39,14 +39,14 @@ export class ShiftsUpsertService {
|
|||
try {
|
||||
const normed = await this.normalizeShiftDto(dto);
|
||||
if (normed.end_time <= normed.start_time) {
|
||||
const error = new ConflictException({
|
||||
const error = {
|
||||
error_code: 'SHIFT_OVERLAP',
|
||||
conflicts: [{
|
||||
conflicts: {
|
||||
start_time: toStringFromHHmm(normed.start_time),
|
||||
end_time: toStringFromHHmm(normed.end_time),
|
||||
date: toStringFromDate(normed.date),
|
||||
}],
|
||||
});
|
||||
},
|
||||
};
|
||||
return { index, error };
|
||||
}
|
||||
if(!normed.end_time) throw new BadRequestException('A shift needs an end_time');
|
||||
|
|
@ -57,14 +57,14 @@ export class ShiftsUpsertService {
|
|||
select: timesheet_select,
|
||||
});
|
||||
if (!timesheet) {
|
||||
const error = new ConflictException({
|
||||
const error = {
|
||||
error_code: 'INVALID_TIMESHEET',
|
||||
conflicts: [{
|
||||
conflicts: {
|
||||
start_time: toStringFromHHmm(normed.start_time),
|
||||
end_time: toStringFromHHmm(normed.end_time),
|
||||
date: toStringFromDate(normed.date),
|
||||
}],
|
||||
});
|
||||
},
|
||||
};
|
||||
return { index, error };
|
||||
}
|
||||
|
||||
|
|
@ -121,11 +121,11 @@ export class ShiftsUpsertService {
|
|||
) {
|
||||
const error = new ConflictException({
|
||||
error_code: 'SHIFT_OVERLAP',
|
||||
conflicts: [{
|
||||
conflicts: {
|
||||
start_time: toStringFromHHmm(ordered[j].start),
|
||||
end_time: toStringFromHHmm(ordered[j].end),
|
||||
date: toStringFromDate(ordered[j].date),
|
||||
}],
|
||||
},
|
||||
});
|
||||
return dtos.map((_dto, key) =>
|
||||
indices.includes(key)
|
||||
|
|
@ -169,14 +169,14 @@ export class ShiftsUpsertService {
|
|||
if (hit) {
|
||||
results[index] = {
|
||||
ok: false,
|
||||
error: new ConflictException({
|
||||
error: {
|
||||
error_code: 'SHIFT_OVERLAP',
|
||||
conflicts: [{
|
||||
conflicts: {
|
||||
start_time: toStringFromHHmm(hit.start_time),
|
||||
end_time: toStringFromHHmm(hit.end_time),
|
||||
date: toStringFromDate(hit.date),
|
||||
}],
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
continue;
|
||||
}
|
||||
|
|
@ -327,14 +327,14 @@ export class ShiftsUpsertService {
|
|||
return updates.map(exist =>
|
||||
exist.id === planned.exist_shift.id
|
||||
? ({
|
||||
ok: false, id: exist.id, error: new ConflictException({
|
||||
ok: false, id: exist.id, error:{
|
||||
error_code: 'SHIFT_OVERLAP',
|
||||
conflicts: [{
|
||||
conflicts: {
|
||||
start_time: toStringFromHHmm(conflict.start),
|
||||
end_time: toStringFromHHmm(conflict.end),
|
||||
date: toStringFromDate(conflict.date),
|
||||
}],
|
||||
})
|
||||
},
|
||||
}
|
||||
} as UpdateShiftResult)
|
||||
: ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to overlap in another update') })
|
||||
);
|
||||
|
|
@ -360,15 +360,15 @@ export class ShiftsUpsertService {
|
|||
{ start: arr[i - 1].start, end: arr[i - 1].end, date: arr[i - 1].date },
|
||||
{ start: arr[i].start, end: arr[i].end, date: arr[i].date })
|
||||
) {
|
||||
const error = new ConflictException({
|
||||
const error = {
|
||||
error_code: 'SHIFT_OVERLAP',
|
||||
conflicts: [{
|
||||
conflicts: {
|
||||
start_time: toStringFromHHmm(arr[i].start),
|
||||
end_time: toStringFromHHmm(arr[i].end),
|
||||
date: toStringFromDate(arr[i].date),
|
||||
}],
|
||||
},
|
||||
|
||||
});
|
||||
};
|
||||
return updates.map(exist => ({ ok: false, id: exist.id, error: error }));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user