From 172aa16c03809b745afe5c19ca71ab74a90d63bb Mon Sep 17 00:00:00 2001 From: karilint Date: Wed, 29 Apr 2026 11:25:06 +0300 Subject: [PATCH] Tolerate invalid occurrence reference dates --- backend/src/services/occurrenceService.ts | 46 +++++++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/backend/src/services/occurrenceService.ts b/backend/src/services/occurrenceService.ts index 459894f2..b45460d4 100644 --- a/backend/src/services/occurrenceService.ts +++ b/backend/src/services/occurrenceService.ts @@ -119,6 +119,44 @@ type OccurrenceUpdate = { updates: OccurrenceLogRow[] } +const referenceWithoutExactDateSelect = { + rid: true, + ref_type_id: true, + journal_id: true, + title_primary: true, + date_primary: true, + volume: true, + issue: true, + start_page: true, + end_page: true, + publisher: true, + pub_place: true, + title_secondary: true, + date_secondary: true, + title_series: true, + issn_isbn: true, + ref_abstract: true, + web_url: true, + misc_1: true, + misc_2: true, + gen_notes: true, + printed_language: true, + used_morph: true, + used_now: true, + used_gene: true, + ref_authors: true, + ref_journal: true, +} as const + +const addNullExactDateToReferences = (references: T[]) => + references.map(reference => ({ + ...reference, + ref_ref: { + ...reference.ref_ref, + exact_date: null, + }, + })) + const stringifyLogValue = (value: unknown) => { if (value === null || value === undefined) return '' if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return String(value) @@ -193,7 +231,7 @@ const getOccurrenceUpdates = async (lid: number, speciesId: number) => { now_lr: { include: { ref_ref: { - include: { ref_authors: true, ref_journal: true }, + select: referenceWithoutExactDateSelect, }, }, }, @@ -207,7 +245,7 @@ const getOccurrenceUpdates = async (lid: number, speciesId: number) => { now_sr: { include: { ref_ref: { - include: { ref_authors: true, ref_journal: true }, + select: referenceWithoutExactDateSelect, }, }, }, @@ -233,7 +271,7 @@ const getOccurrenceUpdates = async (lid: number, speciesId: number) => { update.lau_coordinator ), occ_comment: update.lau_comment ?? '', - references: update.now_lr as unknown as AnyReference[], + references: addNullExactDateToReferences(update.now_lr) as unknown as AnyReference[], updates: nowLsLogs.filter(logRow => logRow.luid === update.luid), })), ...speciesUpdates.map(update => ({ @@ -247,7 +285,7 @@ const getOccurrenceUpdates = async (lid: number, speciesId: number) => { update.sau_coordinator ), occ_comment: update.sau_comment ?? '', - references: update.now_sr as unknown as AnyReference[], + references: addNullExactDateToReferences(update.now_sr) as unknown as AnyReference[], updates: nowLsLogs.filter(logRow => logRow.suid === update.suid), })), ])