Create time update summaries for time unit writes

This commit is contained in:
karilint
2026-05-27 19:12:00 +03:00
parent a4bf5c050a
commit 3e201043ec
6 changed files with 44 additions and 2 deletions
@@ -71,7 +71,15 @@ describe('Creating new time unit', () => {
it('Update logs are correct', () => {
const lastUpdate = createdTimeUnit!.now_tau[createdTimeUnit!.now_tau.length - 1]
const lastSummary = createdTimeUnit!.now_time_update[createdTimeUnit!.now_time_update.length - 1]
expect(lastUpdate.tau_comment).toEqual(newTimeUnitBasis.comment) // 'Comment is correct'
expect(lastSummary).toEqual(
expect.objectContaining({
tu_name: createdTimeUnit!.tu_name,
tuid: lastUpdate.tuid,
now_tau: expect.objectContaining({ tuid: lastUpdate.tuid }),
})
)
const logRows = lastUpdate.updates
const expectedLogRows: Partial<LogRow>[] = [
{
@@ -104,7 +104,15 @@ describe('Time unit updating works', () => {
const { body: createdTimeUnit } = await send<TimeUnitDetailsType>(`time-unit/${existingTimeUnit.tu_name}`, 'GET')
const lastUpdate = createdTimeUnit.now_tau[createdTimeUnit.now_tau.length - 1]
const lastSummary = createdTimeUnit.now_time_update[createdTimeUnit.now_time_update.length - 1]
expect(lastUpdate.tau_comment).toEqual(editedTimeUnit.comment) // 'Comment is correct'
expect(lastSummary).toEqual(
expect.objectContaining({
tu_name: existingTimeUnit.tu_name,
tuid: lastUpdate.tuid,
now_tau: expect.objectContaining({ tuid: lastUpdate.tuid }),
})
)
const logRows = lastUpdate.updates
const expectedLogRows: Partial<LogRow>[] = [
{
+1 -1
View File
@@ -134,7 +134,7 @@ const getTimeUnitWriteHandler = (type: ActionType) => {
dbName: NOW_DB_NAME,
table: 'now_time_unit',
idColumn: 'tu_name',
allowedColumns: getFieldsOfTables(['now_time_unit', 'now_tu_sequence', 'now_tau', 'now_tr']),
allowedColumns: getFieldsOfTables(['now_time_unit', 'now_tu_sequence', 'now_tau', 'now_tr', 'now_time_update']),
type,
})
}
@@ -17,6 +17,7 @@ export type AllowedTables =
| 'now_sau'
| 'now_tau'
| 'now_bau'
| 'now_time_update'
export type PrimaryTables = 'now_loc' | 'com_species' | 'now_time_unit' | 'now_tu_bound' | 'ref_ref'
@@ -3,7 +3,7 @@ import { COORDINATOR } from '../../../../utils/config'
import { AllowedTables, ActionType, Item, LogRow, PrimaryTables, WriteItem, UpdateEntry } from '../types'
import { WriteHandler } from '../writeHandler'
import { filterRelevantLogRows, prefixToIdColumn, primaryTableToUpdatePrefix, tableToUpdateTargets } from './utils'
import { createUpdateEntry, writeLogRows, writeReferences } from './writeUpdates'
import { createTimeUpdateSummary, createUpdateEntry, writeLogRows, writeReferences } from './writeUpdates'
export const logAllUpdates = async (
writeHandler: WriteHandler,
@@ -157,6 +157,9 @@ const writeUpdateEntries = async (
const prefix = primaryTableToUpdatePrefix[updateEntry.table]
const createdId = await createUpdateEntry(writeHandler, prefix, COORDINATOR, authorizer, comment, updateEntry.id)
updateEntry.entryId = createdId
if (updateEntry.table === 'now_time_unit') {
await createTimeUpdateSummary(writeHandler, updateEntry.id, createdId, COORDINATOR, authorizer, comment)
}
}
return updateEntries
}
@@ -57,6 +57,28 @@ export const createUpdateEntry = async (
return result[idField] as number
}
export const createTimeUpdateSummary = async (
writeHandler: WriteHandler,
tuName: string | number,
tuid: number,
coordinator: string,
authorizer: string,
comment: string
) => {
await writeHandler.createObject(
'now_time_update',
{
tu_name: String(tuName),
tuid,
coordinator,
authorizer,
date: getFormattedDate(),
comment,
},
['time_update_id']
)
}
export const writeReferences = async (
writeHandler: WriteHandler,
updateEntries: UpdateEntry[],