fastify-mongoose-rest
Version:
Rest API generator tools for fastify and mongoose
61 lines • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Delete = void 0;
function Delete(basePath, model, options) {
const response = {
200: {
description: 'Success',
type: 'object',
properties: {
acknowledged: { type: 'boolean' },
deletedCount: { type: 'number' },
},
},
404: {
description: 'Not found',
type: 'object',
properties: {
error: { type: 'string' },
message: { type: 'string' },
},
},
500: {
description: 'Server error',
type: 'object',
properties: {
error: { type: 'string' },
message: { type: 'string' },
},
},
};
const { tags, findProperty } = options;
return {
method: 'DELETE',
url: `${basePath}/:id`,
schema: {
summary: `Delete a ${model.modelName} resource`,
tags,
params: {
type: 'object',
properties: {
id: {
type: 'string',
description: `Unique identifier of ${model.modelName}`,
},
},
},
response,
},
handler: async (request, reply) => {
const result = await model.deleteOne({
[findProperty || '_id']: request.params.id,
});
if (result.deletedCount < 1) {
return reply.status(404).send(new Error('Resource not found'));
}
return reply.send(result);
},
};
}
exports.Delete = Delete;
//# sourceMappingURL=delete.js.map