mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Create time update summaries for time unit writes
This commit is contained in:
@@ -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>[] = [
|
||||
{
|
||||
|
||||
@@ -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[],
|
||||
|
||||
Reference in New Issue
Block a user