simplify post endpoint

This commit is contained in:
Morten Olsen
2025-11-03 17:10:33 +01:00
parent 0c70f363df
commit 2f542c3066

View File

@@ -15,20 +15,15 @@ const documentsPlugin: FastifyPluginAsyncZod = async (app) => {
operationId: 'v1.documents.put',
tags: ['documents'],
summary: 'Upsert documents',
body: z.object({
items: z.array(upsertDocumentRequestSchema),
}),
body: upsertDocumentRequestSchema,
response: {
200: z.object({
items: z.array(upsertDocumentResponseSchema),
}),
200: upsertDocumentResponseSchema,
},
},
handler: async (req, reply) => {
const documentsService = app.services.get(DocumentsService);
const { items } = req.body;
const results = await Promise.all(items.map((item) => documentsService.upsert(item)));
return reply.send({ items: results });
const result = await documentsService.upsert(req.body);
return reply.send(result);
},
});
};