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', 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 });
}, },
}); });
}; };