Error handling on empty damaged parts

This commit is contained in:
2026-06-19 13:40:38 +03:30
parent 761f0cb679
commit 5cada3c6c8

View File

@@ -4655,7 +4655,7 @@ export class ExpertClaimService {
previousNorm,
);
const nextNorm = body.selectedParts.map((p) =>
const nextNormRaw = body.selectedParts.map((p) =>
sanitizeDamageSelectedPartV2(
{
id: p.id ?? null,
@@ -4669,6 +4669,20 @@ export class ExpertClaimService {
),
);
// Drop ghost entries: internal parts with neither a catalog id nor a name
// (these are frontend artifacts from uninitialised form rows).
const nextNorm = nextNormRaw.filter((p) => {
if (p.id != null) return true;
return String(p.name ?? "").trim().length > 0;
});
if (nextNorm.length === 0) {
throw new BadRequestException(
"selectedParts must contain at least one identifiable part. " +
"Each entry must have a numeric catalog id or a non-empty name.",
);
}
const matchPreviousIndex = (
next: (typeof nextNorm)[0],
previous: typeof previousNorm,