mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Fix prefix of creating update entry
This commit is contained in:
@@ -7,13 +7,13 @@ const getUpdateIdField = (tableName: string) => `${tableName[4]}uid`
|
||||
|
||||
export const createUpdateEntry = async (
|
||||
conn: PoolConnection,
|
||||
prefix: 's' | 't' | 'l' | 'b',
|
||||
prefix: 'sau' | 'tau' | 'lau' | 'bau',
|
||||
coordinator: string,
|
||||
authorizer: string,
|
||||
comment: string,
|
||||
id: string | number
|
||||
) => {
|
||||
const table = `now_${prefix}au`
|
||||
const table = `now_${prefix}`
|
||||
const idField = getUpdateIdField(table)
|
||||
const result: object[] = await conn.query(
|
||||
`INSERT INTO ${NOW_DB_NAME}.${table} (${prefix}_coordinator, ${prefix}_authorizer, ${tableToId[table]}, ${prefix}_date, ${prefix}_comment) VALUES (?, ?, ?, ?, ?) RETURNING ${table}.${idField}`,
|
||||
|
||||
@@ -155,18 +155,18 @@ export const write: WriteFunction = async (data, tableName, updateOptions) => {
|
||||
if (updateOptions) {
|
||||
const { authorizer, userName } = updateOptions
|
||||
const tableNameToPrefix = {
|
||||
now_loc: 'l',
|
||||
com_species: 's',
|
||||
now_time_unit: 't',
|
||||
now_tu_bound: 'b',
|
||||
} as Record<AllowedTables, 's' | 't' | 'l' | 'b'>
|
||||
now_loc: 'lau',
|
||||
com_species: 'sau',
|
||||
now_time_unit: 'tau',
|
||||
now_tu_bound: 'bau',
|
||||
} as Record<AllowedTables, 'sau' | 'tau' | 'lau' | 'bau'>
|
||||
const prefix = tableNameToPrefix[tableName]
|
||||
const updateEntry = await createUpdateEntry(
|
||||
conn,
|
||||
prefix,
|
||||
COORDINATOR,
|
||||
authorizer,
|
||||
(data[`now_${prefix}au`] as { comment: string }).comment,
|
||||
(data[`now_${prefix}`] as { comment: string }).comment,
|
||||
result
|
||||
)
|
||||
debugLog(`updateEntry: ${printJSON(updateEntry)}`, true)
|
||||
|
||||
Reference in New Issue
Block a user