UNPKG

@eleva-io/erp-sdk

Version:

SDK oficial para el ERP de Eleva

72 lines 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CRUD = void 0; const DEFAULT_METHODS_CONFIG = { isCreateEnabled: true, isReadEnabled: true, isUpdateEnabled: true, isDeleteEnabled: true, isFindEnabled: true, }; class CRUD { _httpClient; _config; constructor(_httpClient, _config) { this._httpClient = _httpClient; this._config = _config; this._config = { ...this._config, methods: { ...DEFAULT_METHODS_CONFIG, ..._config.methods, }, }; } async get(id) { if (!this._config.methods.isReadEnabled) { throw new Error('Read method is not enabled'); } const idParam = this._getIdParam(id); const path = `${this._config.basePath}/${idParam}`; return this._httpClient.get(path); } async create(data) { if (!this._config.methods.isCreateEnabled) { throw new Error('Create method is not enabled'); } const path = `${this._config.basePath}`; return this._httpClient.post(path, data); } async update(id, data) { if (!this._config.methods.isUpdateEnabled) { throw new Error('Update method is not enabled'); } const idParam = this._getIdParam(id); const path = `${this._config.basePath}/${idParam}`; return this._httpClient.patch(path, data); } async delete(id) { if (!this._config.methods.isDeleteEnabled) { throw new Error('Delete method is not enabled'); } const idParam = this._getIdParam(id); const path = `${this._config.basePath}/${idParam}`; return this._httpClient.delete(path); } async find(query) { if (!this._config.methods.isFindEnabled) { throw new Error('Find method is not enabled'); } const path = `${this._config.basePath}`; return this._httpClient.get(path, query); } _getIdParam(id) { const idParam = id || this._config.id; if (!idParam) { throw new Error('ID is required'); } return idParam; } } exports.CRUD = CRUD; //# sourceMappingURL=crud.js.map