UNPKG

fastify-mongoose-rest

Version:

Rest API generator tools for fastify and mongoose

54 lines 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const helpers_1 = require("../helpers"); function Details(name, model, options) { let response = {}; if (options === null || options === void 0 ? void 0 : options.validationSchema) { response = helpers_1.createResponseSchema(options.validationSchema, 'object'); } return { method: 'GET', url: `/${name}/:id`, schema: { summary: `Get details of single ${name}`, tags: (options === null || options === void 0 ? void 0 : options.tags) || [], params: { type: 'object', properties: { id: { type: 'string', description: `Unique identifier of ${name}`, }, }, }, querystring: { type: 'object', properties: { populate: { type: 'string', description: 'Population options of mongoose', }, projection: { type: 'string', description: 'Projection options of mongoose', }, }, }, response, }, handler: async (request, reply) => { const { populate, projection } = request.query; const query = model.findById(request.params.id); if (populate) { query.populate(helpers_1.parseInput(populate)); } if (projection) { query.projection(helpers_1.parseInput(projection)); } const resource = await query.exec(); return reply.send(resource); }, }; } exports.default = Details; //# sourceMappingURL=details.js.map