mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Fix 5
This commit is contained in:
@@ -91,17 +91,25 @@ const collectUniqueIds = (rows: OccurrenceLogRow[], fieldName: 'luid' | 'suid')
|
||||
const isOccurrenceLogCandidate = (row: RawOccurrenceLogRow): row is OccurrenceLogCandidate =>
|
||||
row.table_name === 'now_ls' && typeof row.pk_data === 'string'
|
||||
|
||||
const matchesOccurrenceSpeciesPk =
|
||||
(speciesPk: string) =>
|
||||
(row: OccurrenceLogCandidate): boolean =>
|
||||
row.pk_data.includes(speciesPk)
|
||||
|
||||
const normalizeOccurrenceLogRow = (row: OccurrenceLogCandidate): OccurrenceLogRow => ({
|
||||
...row,
|
||||
luid: readNumericField(row, 'luid'),
|
||||
suid: readNumericField(row, 'suid'),
|
||||
})
|
||||
|
||||
const getOccurrenceLogRows = (rows: RawOccurrenceLogRow[], speciesPk: string): OccurrenceLogRow[] => {
|
||||
const occurrenceRows: OccurrenceLogRow[] = []
|
||||
|
||||
for (const row of rows) {
|
||||
if (!isOccurrenceLogCandidate(row)) continue
|
||||
if (!row.pk_data.includes(speciesPk)) continue
|
||||
|
||||
occurrenceRows.push(normalizeOccurrenceLogRow(row))
|
||||
}
|
||||
|
||||
return occurrenceRows
|
||||
}
|
||||
|
||||
type OccurrenceUpdate = {
|
||||
occ_date: Date | null
|
||||
occ_authorizer: string
|
||||
@@ -172,10 +180,7 @@ const getOccurrenceUpdates = async (lid: number, speciesId: number) => {
|
||||
},
|
||||
})
|
||||
|
||||
const nowLsLogs = candidateLogsRaw
|
||||
.filter(isOccurrenceLogCandidate)
|
||||
.filter(matchesOccurrenceSpeciesPk(speciesPk))
|
||||
.map(normalizeOccurrenceLogRow)
|
||||
const nowLsLogs = getOccurrenceLogRows(candidateLogsRaw, speciesPk)
|
||||
|
||||
const luids = collectUniqueIds(nowLsLogs, 'luid')
|
||||
const suids = collectUniqueIds(nowLsLogs, 'suid')
|
||||
|
||||
Reference in New Issue
Block a user