feat(F-103): completed feature

This commit is contained in:
chattie
2026-08-21 07:55:18 +02:00
parent 5177a851aa
commit c07776822d
40 changed files with 886 additions and 156 deletions

View File

@@ -153,13 +153,30 @@ export async function registerOrdersRoutes(
const listOrdersSchema: FastifySchema = {
tags: ['Orders'],
summary: 'List orders (admin)',
querystring: {
type: 'object',
properties: {
status: { type: 'string', description: 'Filtro por estado del pedido' },
q: { type: 'string', maxLength: 120, description: 'Búsqueda por ID o email del cliente' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 20 },
offset: { type: 'integer', minimum: 0, default: 0 },
},
},
response: { 401: errorSchema, 403: errorSchema },
};
app.get('/orders', { schema: listOrdersSchema }, async (request, reply) => {
const user = await deps.authenticate(request);
requireRole(user, 'admin');
const orders = await service.listOrders();
return reply.send(orders.map(serializeOrder));
const query = request.query as { status?: string; q?: string; limit?: string; offset?: string };
const limit = Math.min(Math.max(Number(query.limit ?? 20) || 20, 1), 100);
const offset = Math.max(Number(query.offset ?? 0) || 0, 0);
const { items, total } = await service.searchOrders({
state: query.status?.trim() || undefined,
q: query.q?.trim() || undefined,
limit,
offset,
});
return reply.send({ items: items.map(serializeOrder), total });
});
const getOrderAdminSchema: FastifySchema = {