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