mongodb-dynamic-api
Version:
Auto generated CRUD API for MongoDB using NestJS
33 lines • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseGetOneService = void 0;
const services_1 = require("../../services");
class BaseGetOneService extends services_1.BaseService {
constructor(model) {
super(model);
this.model = model;
}
async getOne(id) {
try {
const document = await this.model
.findOne({
_id: id,
...(this.isSoftDeletable ? { isDeleted: false } : undefined),
})
.lean()
.exec();
if (!document) {
this.handleDocumentNotFound();
}
if (this.callback) {
await this.callback(this.addDocumentId(document), this.callbackMethods);
}
return this.buildInstance(document);
}
catch (error) {
this.handleMongoErrors(error);
}
}
}
exports.BaseGetOneService = BaseGetOneService;
//# sourceMappingURL=base-get-one.service.js.map