mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Use coordinator from env, cleanup code
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Request, Router } from 'express'
|
||||
import { getAllLocalities, getLocalityDetails, processLocalityForEdit } from '../services/locality'
|
||||
import { getAllLocalities, getLocalityDetails, validateEntireLocality } from '../services/locality'
|
||||
import { fixBigInt } from '../utils/common'
|
||||
import { EditDataType, LocalityDetailsType } from '../../../frontend/src/backendTypes'
|
||||
import { write } from '../services/write/write'
|
||||
|
||||
const router = Router()
|
||||
|
||||
@@ -19,10 +20,11 @@ router.get('/:id', async (req, res) => {
|
||||
|
||||
router.put('/', async (req: Request<object, object, { locality: EditDataType<LocalityDetailsType> }>, res) => {
|
||||
const editedLocality = req.body.locality
|
||||
const { validationErrors, result } = await processLocalityForEdit(editedLocality)
|
||||
const validationErrors = validateEntireLocality(editedLocality)
|
||||
if (validationErrors) {
|
||||
return res.status(400).send({ validationErrors })
|
||||
}
|
||||
const result = await write(editedLocality, 'now_loc', { authorizer: 'NA', userName: 'testuser' })
|
||||
return res.status(200).send(result ? { result: result } : { error: 'error' })
|
||||
})
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Router } from 'express'
|
||||
import { getAllSpecies, getSpeciesDetails } from '../services/species'
|
||||
import { fixBigInt } from '../utils/common'
|
||||
import { EditDataType, SpeciesDetailsType } from '../../../frontend/src/backendTypes'
|
||||
import { SpeciesDetailsType } from '../../../frontend/src/backendTypes'
|
||||
import { write } from '../services/write/write'
|
||||
|
||||
const router = Router()
|
||||
@@ -19,10 +19,9 @@ router.get('/:id', async (req, res) => {
|
||||
})
|
||||
|
||||
router.put('/', async (req: Request<object, object, { species: SpeciesDetailsType }>, res) => {
|
||||
const editedObject = req.body.species
|
||||
const result = await write(editedObject, 'com_species', {
|
||||
const editedSpecies = req.body.species
|
||||
const result = await write(editedSpecies, 'com_species', {
|
||||
authorizer: 'ArK',
|
||||
coordinator: 'ArK',
|
||||
userName: 'testuser',
|
||||
})
|
||||
return res.status(200).send(result ? { result: result } : { error: 'error' })
|
||||
|
||||
@@ -25,7 +25,7 @@ router.get('/time-units/:id', async (req, res) => {
|
||||
|
||||
router.put('/', async (req: Request<object, object, { timeBound: EditDataType<TimeBoundDetailsType> }>, res) => {
|
||||
const editedObject = req.body.timeBound
|
||||
const result = await write(editedObject, 'now_time_unit', 'ArK', 'ArK', 'testuser')
|
||||
const result = await write(editedObject, 'now_time_unit', { userName: 'testuser', authorizer: 'ArK' })
|
||||
return res.status(200).send(result ? { result: result } : { error: 'error' })
|
||||
})
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ router.get('/localities/:id', async (req, res) => {
|
||||
|
||||
router.put('/', async (req: Request<object, object, { timeUnit: EditDataType<TimeUnitDetailsType> }>, res) => {
|
||||
const editedObject = req.body.timeUnit
|
||||
const result = await write(editedObject, 'now_time_unit', 'ArK', 'ArK', 'testuser')
|
||||
const result = await write(editedObject, 'now_time_unit', { userName: 'testuser', authorizer: 'ArK' })
|
||||
return res.status(200).send(result ? { result: result } : { error: 'error' })
|
||||
})
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
export const writeLocalitySpecies = (lid: number, species_id: number) => {
|
||||
/*
|
||||
write com_species
|
||||
write each ls, appending lid and species_id
|
||||
*/
|
||||
}
|
||||
|
||||
export const writeLocality = () => {
|
||||
// writeLocalitySpecies
|
||||
// writeMuseums
|
||||
// write
|
||||
}
|
||||
|
||||
export const writeMuseums = () => {
|
||||
/*
|
||||
now_ls, now_mus, now_plr, now_ss, now_syn_loc
|
||||
*/
|
||||
}
|
||||
|
||||
export const writeSynLocs = () => {
|
||||
/*
|
||||
|
||||
*/
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
isEmptyValue,
|
||||
printJSON,
|
||||
} from './writeUtils'
|
||||
import { NOW_DB_NAME } from '../../utils/config'
|
||||
import { COORDINATOR, NOW_DB_NAME } from '../../utils/config'
|
||||
import { createUpdateEntry, writeToLog } from './updateAndLog'
|
||||
|
||||
export const write: WriteFunction = async (data, tableName, updateOptions) => {
|
||||
@@ -97,7 +97,7 @@ export const write: WriteFunction = async (data, tableName, updateOptions) => {
|
||||
if (id && !!oldObj) {
|
||||
await query(
|
||||
`UPDATE ${NOW_DB_NAME}.${tableName} SET ${columns.map(c => `${c} = ?`).join(', ')} WHERE ${idFieldName} = ?`,
|
||||
[...values, id]
|
||||
[...values, id] as never
|
||||
)
|
||||
type = 'update'
|
||||
} else {
|
||||
@@ -153,7 +153,7 @@ export const write: WriteFunction = async (data, tableName, updateOptions) => {
|
||||
debugLog(`Final result: ${printJSON(result)}`)
|
||||
debugLog(`WriteList: ${printJSON(writeList)}`)
|
||||
if (updateOptions) {
|
||||
const { coordinator, authorizer, userName } = updateOptions
|
||||
const { authorizer, userName } = updateOptions
|
||||
const tableNameToPrefix = {
|
||||
now_loc: 'l',
|
||||
com_species: 's',
|
||||
@@ -164,7 +164,7 @@ export const write: WriteFunction = async (data, tableName, updateOptions) => {
|
||||
const updateEntry = await createUpdateEntry(
|
||||
conn,
|
||||
prefix,
|
||||
coordinator,
|
||||
COORDINATOR,
|
||||
authorizer,
|
||||
(data[`now_${prefix}au`] as { comment: string }).comment,
|
||||
result
|
||||
|
||||
@@ -76,7 +76,6 @@ export type WriteFunction = <T extends CustomObject>(
|
||||
tableName: AllowedTables,
|
||||
updateOptions?: {
|
||||
authorizer: string
|
||||
coordinator: string
|
||||
userName: string
|
||||
}
|
||||
) =>
|
||||
|
||||
Vendored
+2
-2
@@ -11,8 +11,8 @@ type EditDataType<T> = T extends object
|
||||
: never
|
||||
: T
|
||||
|
||||
type FixBigInt<T> = {
|
||||
[K in keyof T]: T[K] extends bigint
|
||||
export type FixBigInt<T> = {
|
||||
[K in keyof T]: T[K] extends bigint | null
|
||||
? number
|
||||
: T[K] extends (infer U)[]
|
||||
? FixBigInt<U>[]
|
||||
|
||||
Reference in New Issue
Block a user