Skip to content

Commit 6fd3b24

Browse files
committed
wip
1 parent f5a6782 commit 6fd3b24

File tree

1 file changed

+7
-36
lines changed

1 file changed

+7
-36
lines changed

src/server/routes/columns.ts

+7-36
Original file line numberDiff line numberDiff line change
@@ -55,51 +55,18 @@ export default async (fastify: FastifyInstance) => {
5555
return data
5656
})
5757

58-
fastify.get<{
59-
Headers: { pg: string }
60-
Body: any
61-
}>('/batch', async (request, reply) => {
62-
const connectionString = request.headers.pg
63-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
64-
const { data, error } = await pgMeta.columns.batchRetrieve({ ids: request.body })
65-
await pgMeta.end()
66-
if (error) {
67-
request.log.error({ error, request: extractRequestForLogging(request) })
68-
reply.code(400)
69-
if (error.message.startsWith('Cannot find')) reply.code(404)
70-
return { error: error.message }
71-
}
72-
73-
return data
74-
})
75-
7658
// deprecated: use POST /batch instead
7759
// TODO (darora): specifying a schema on the routes would both allow for validation, and enable us to mark methods as deprecated
7860
fastify.post<{
7961
Headers: { pg: string }
8062
Body: any
8163
}>('/', async (request, reply) => {
8264
const connectionString = request.headers.pg
83-
8465
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
85-
const { data, error } = await pgMeta.columns.create(request.body)
86-
await pgMeta.end()
87-
if (error) {
88-
request.log.error({ error, request: extractRequestForLogging(request) })
89-
reply.code(400)
90-
if (error.message.startsWith('Cannot find')) reply.code(404)
91-
return { error: error.message }
66+
if (!Array.isArray(request.body)) {
67+
request.body = [request.body]
9268
}
93-
return data
94-
})
9569

96-
fastify.post<{
97-
Headers: { pg: string }
98-
Body: any
99-
}>('/batch', async (request, reply) => {
100-
const connectionString = request.headers.pg
101-
102-
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
10370
const { data, error } = await pgMeta.columns.batchCreate(request.body)
10471
await pgMeta.end()
10572
if (error) {
@@ -108,7 +75,11 @@ export default async (fastify: FastifyInstance) => {
10875
if (error.message.startsWith('Cannot find')) reply.code(404)
10976
return { error: error.message }
11077
}
111-
return data
78+
79+
if (Array.isArray(request.body)) {
80+
return data
81+
}
82+
return data[0]
11283
})
11384

11485
fastify.patch<{

0 commit comments

Comments
 (0)