mirror of
https://github.com/morten-olsen/reservoir.git
synced 2026-02-08 01:46:24 +01:00
simplify post endpoint
This commit is contained in:
@@ -15,20 +15,15 @@ const documentsPlugin: FastifyPluginAsyncZod = async (app) => {
|
|||||||
operationId: 'v1.documents.put',
|
operationId: 'v1.documents.put',
|
||||||
tags: ['documents'],
|
tags: ['documents'],
|
||||||
summary: 'Upsert documents',
|
summary: 'Upsert documents',
|
||||||
body: z.object({
|
body: upsertDocumentRequestSchema,
|
||||||
items: z.array(upsertDocumentRequestSchema),
|
|
||||||
}),
|
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: upsertDocumentResponseSchema,
|
||||||
items: z.array(upsertDocumentResponseSchema),
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
handler: async (req, reply) => {
|
handler: async (req, reply) => {
|
||||||
const documentsService = app.services.get(DocumentsService);
|
const documentsService = app.services.get(DocumentsService);
|
||||||
const { items } = req.body;
|
const result = await documentsService.upsert(req.body);
|
||||||
const results = await Promise.all(items.map((item) => documentsService.upsert(item)));
|
return reply.send(result);
|
||||||
return reply.send({ items: results });
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user