feat(F-103): completed feature
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user