mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Add edit action type to writeContext, meaning update/add type is logged correctly
This commit is contained in:
@@ -35,7 +35,13 @@ router.put(
|
||||
return res.status(400).send({ validationErrors })
|
||||
}
|
||||
|
||||
const result = await write(editedLocality, 'now_loc', req.user!.initials, comment ?? '')
|
||||
const result = await write(
|
||||
editedLocality,
|
||||
'now_loc',
|
||||
req.user!.initials,
|
||||
comment ?? '',
|
||||
editedLocality.lid ? 'update' : 'add'
|
||||
)
|
||||
return res.status(200).send(result ? { id: result } : { error: 'error' })
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { pool } from '../../utils/db'
|
||||
import { logger } from '../../utils/logger'
|
||||
import {
|
||||
ActionType,
|
||||
AllowedTables,
|
||||
CustomObject,
|
||||
DbValue,
|
||||
@@ -31,6 +32,7 @@ export type WriteContext = {
|
||||
connection: PoolConnection
|
||||
writeList: WriteItem[]
|
||||
username: string
|
||||
type: ActionType
|
||||
}
|
||||
|
||||
const writeTable = async <T extends CustomObject>(obj: T, tableName: AllowedTables, writeContext: WriteContext) => {
|
||||
@@ -163,7 +165,7 @@ const writeTable = async <T extends CustomObject>(obj: T, tableName: AllowedTabl
|
||||
return id
|
||||
}
|
||||
|
||||
export const write: WriteFunction = async (data, tableName, userInitials, comment) => {
|
||||
export const write: WriteFunction = async (data, tableName, userInitials, comment, type) => {
|
||||
const connection = await pool.getConnection()
|
||||
await connection.beginTransaction()
|
||||
|
||||
@@ -171,6 +173,7 @@ export const write: WriteFunction = async (data, tableName, userInitials, commen
|
||||
connection,
|
||||
writeList: [],
|
||||
username: userInitials,
|
||||
type,
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -72,7 +72,7 @@ export const logAllUpdates = async (
|
||||
}
|
||||
|
||||
const rootUpdateEntry: UpdateEntry = {
|
||||
type: 'add', // TODO fix: this should probably be received as an argument?
|
||||
type: writeContext.type,
|
||||
table: tableName,
|
||||
id,
|
||||
logRows: writeList.flatMap(writeItem =>
|
||||
@@ -280,7 +280,8 @@ export type WriteFunction = <T extends CustomObject>(
|
||||
data: T,
|
||||
tableName: PrimaryTables,
|
||||
username: string,
|
||||
comment: string
|
||||
comment: string,
|
||||
type: ActionType
|
||||
) =>
|
||||
| Promise<string | number>
|
||||
| ((data: EditDataType<ReferenceDetailsType>, tableName: 'ref_ref') => Promise<string | number>)
|
||||
|
||||
Reference in New Issue
Block a user