UNPKG

arrest

Version:

OpenAPI v3 compliant REST framework for Node.js, with support for MongoDB and JSON-Schema

44 lines 1.45 kB
import { API } from '../../api.js'; import { addConstraint } from '../util.js'; import { MongoOperation } from './base.js'; export class RemoveMongoOperation extends MongoOperation { constructor(resource, path, method, id = 'remove') { super(resource, path, method, id); } getCustomInfo() { return { summary: `Delete a ${this.resource.info.name} by id`, parameters: [ { $ref: '#/components/parameters/id', }, ], responses: { '200': { description: `${this.resource.info.name} successfully deleted`, }, '404': { $ref: '#/components/responses/notFound', }, default: { $ref: '#/components/responses/defaultError', }, }, }; } async prepareQuery(job) { job = await super.prepareQuery(job); job.query = addConstraint(job.query, this.getItemQuery(job.req.params.id)); return job; } async runOperation(job) { let opts = job.opts; let result = await job.coll.deleteOne(job.query, opts); if (result.deletedCount != 1) { job.req.logger.error('delete failed', result); API.fireError(404, 'not_found'); } return job; } } //# sourceMappingURL=remove.js.map