arrest
Version:
OpenAPI v3 compliant REST framework for Node.js, with support for MongoDB and JSON-Schema
51 lines • 1.63 kB
JavaScript
import { API } from '../../api.js';
import { addConstraint } from '../util.js';
import { MongoOperation } from './base.js';
export class ReadMongoOperation extends MongoOperation {
constructor(resource, path, method, id = 'read') {
super(resource, path, method, id);
}
getCustomInfo() {
return {
summary: `Retrieve a ${this.resource.info.name} by id`,
parameters: [
{
$ref: '#/components/parameters/id',
},
{
$ref: '#/components/parameters/fields',
},
],
responses: {
'200': {
description: `The requested ${this.resource.info.name}`,
content: {
'application/json': {
schema: this.responseSchema,
},
},
},
'404': {
$ref: '#/components/responses/notFound',
},
},
};
}
async prepareQuery(job) {
job = await super.prepareQuery(job);
job.query = addConstraint(job.query, this.getItemQuery(job.req.params.id));
return job;
}
async prepareOpts(job) {
job.opts.projection = this.parseFields(job.req.query.fields);
return job;
}
async runOperation(job) {
job.data = await job.coll.findOne(job.query, job.opts);
if (!job.data) {
API.fireError(404, 'not_found');
}
return job;
}
}
//# sourceMappingURL=read.js.map