UNPKG

fastify-mongoose-rest

Version:

Rest API generator tools for fastify and mongoose

41 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const helpers_1 = require("../helpers"); function Modify(name, model, options) { let body = { type: 'object' }; let response = {}; if (options === null || options === void 0 ? void 0 : options.validationSchema) { body = { type: 'object', properties: { ...options.validationSchema, }, }; delete body.properties._id; response = helpers_1.createResponseSchema(options.validationSchema, 'object'); } return { method: 'PATCH', url: `/${name}/:id`, schema: { summary: `Modify existing ${name}`, tags: (options === null || options === void 0 ? void 0 : options.tags) || [], params: { type: 'object', properties: { id: { type: 'string' }, }, }, body, response, }, handler: async (request, reply) => { let resource = await model.findById(request.params.id).lean(); resource = helpers_1.updatePropertiesRecursive(resource, request.body); await model.updateOne({ _id: request.params.id }, { $set: resource }); return reply.send(resource); }, }; } exports.default = Modify; //# sourceMappingURL=modify.js.map