1
0
forked from Yara724/api

Merge pull request 'Error handling on empty damaged parts' (#134) from s.yahyaee/yara724-api:main into main

Reviewed-on: Yara724/api#134
This commit is contained in:
2026-06-19 13:41:21 +03:30

View File

@@ -4655,7 +4655,7 @@ export class ExpertClaimService {
previousNorm, previousNorm,
); );
const nextNorm = body.selectedParts.map((p) => const nextNormRaw = body.selectedParts.map((p) =>
sanitizeDamageSelectedPartV2( sanitizeDamageSelectedPartV2(
{ {
id: p.id ?? null, 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 = ( const matchPreviousIndex = (
next: (typeof nextNorm)[0], next: (typeof nextNorm)[0],
previous: typeof previousNorm, previous: typeof previousNorm,