UNPKG

fastify-mongoose-rest

Version:

Rest API generator tools for fastify and mongoose

82 lines 2.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.List = void 0; const utils_1 = require("../utils"); function List(basePath, model, options) { const { tags, validationSchema } = options; let response = {}; if (validationSchema) { response = (0, utils_1.createResponseSchema)(validationSchema, 'array'); } return { method: 'GET', url: `${basePath}`, schema: { summary: `List ${model.modelName} resources`, tags, querystring: { type: 'object', properties: { query: { type: 'string', description: 'Mongoose find query', }, q: { type: 'string', description: 'Mongoose find query', }, populate: { type: 'string', description: 'Population options of mongoose', }, projection: { type: 'string', description: 'Projection options of mongoose', }, sort: { type: 'string', description: 'Sort options of mongoose', }, select: { type: 'string', description: 'Select options of mongoose', }, skip: { type: 'integer', description: 'Mongoose skip property', }, limit: { type: 'integer', description: 'Mongoose limit property', }, p: { type: 'integer', description: 'Page number property', }, page: { type: 'integer', description: 'Page number property', }, pageSize: { type: 'integer', description: 'PageSize property', }, totalCount: { type: 'boolean', description: 'Should endpoint return X-Total-Count header', }, }, }, response, }, handler: async (request, reply) => { const { resources, totalCount } = await (0, utils_1.findOperation)(model, request.query); if (totalCount !== undefined) { reply.header('X-Total-Count', totalCount); } return reply.send(resources); }, }; } exports.List = List; //# sourceMappingURL=list.js.map