UNPKG

@minimaltech/node-infra

Version:

Minimal Technology NodeJS Infrastructure - Loopback 4 Framework

67 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseCrudService = void 0; const base_service_1 = require("./base.service"); const common_1 = require("../controllers/common"); class BaseCrudService extends base_service_1.BaseService { constructor(opts) { const { scope, repository } = opts; super({ scope }); this.repository = repository; } find(filter, _options) { return this.repository.find((0, common_1.applyLimit)(filter)); } findById(id, filter, _options) { return this.repository.findById(id, (0, common_1.applyLimit)(filter)); } findOne(filter, _options) { return this.repository.findOne(filter); } count(where, _options) { return this.repository.count(where); } create(data, options) { var _a; return this.repository.create(data, { authorId: (_a = options.currentUser) === null || _a === void 0 ? void 0 : _a.userId, }); } updateAll(data, where, options) { var _a; return this.repository.updateAll(data, where, { authorId: (_a = options.currentUser) === null || _a === void 0 ? void 0 : _a.userId, }); } updateWithReturn(id, data, options) { var _a; return this.repository.updateWithReturn(id, data, { authorId: (_a = options.currentUser) === null || _a === void 0 ? void 0 : _a.userId, }); } replaceById(id, data, options) { return new Promise((resolve, reject) => { var _a; this.repository .replaceById(id, data, { authorId: (_a = options.currentUser) === null || _a === void 0 ? void 0 : _a.userId, }) .then(() => { resolve(Object.assign(Object.assign({}, data), { id })); }) .catch(reject); }); } deleteById(id, _options) { return new Promise((resolve, reject) => { this.repository .deleteById(id) .then(() => { resolve({ id }); }) .catch(reject); }); } } exports.BaseCrudService = BaseCrudService; //# sourceMappingURL=base-crud.service.js.map