UNPKG

@crediblex.io/fineract-api-client

Version:
146 lines 6.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FineractDatatableApi = void 0; const errors_1 = require("../types/errors"); /** * API client for Fineract Datatable related operations. * It uses the HttpClient for making requests. */ class FineractDatatableApi { constructor(httpClient) { this.httpClient = httpClient; } /** * Retrieves all datatables from Fineract. * Corresponds to the GET /datatables endpoint. * * @returns A promise that resolves to the list of datatables or rejects with an error. */ async getAll() { try { const apiPath = "/fineract-provider/api/v1/datatables"; const response = await this.httpClient.get(apiPath); return response.data; } catch (rawError) { const errorPayload = rawError; const message = errorPayload?.message || errorPayload?.error || "Fineract API request failed"; throw new errors_1.FineractApiError(message, errorPayload?.statusCode, errorPayload?.details, errorPayload?.error); } } /** * Retrieves a specific datatable by name from Fineract. * Corresponds to the GET /datatables/{datatableName} endpoint. * * @param datatableName The name of the datatable to retrieve. * @returns A promise that resolves to the datatable details or rejects with an error. */ async getByName(datatableName) { try { const apiPath = `/fineract-provider/api/v1/datatables/${datatableName}`; const response = await this.httpClient.get(apiPath); return response.data; } catch (rawError) { const errorPayload = rawError; const message = errorPayload?.message || errorPayload?.error || "Fineract API request failed"; throw new errors_1.FineractApiError(message, errorPayload?.statusCode, errorPayload?.details, errorPayload?.error); } } /** * Retrieves datatable entries for a specific entity. * Corresponds to the GET /datatables/{datatableName}/{entityId} endpoint. * * @param datatableName The name of the datatable. * @param entityId The id of the entity (e.g. m_client.id) to retrieve datatable entries for. * @returns A promise that resolves to the datatable entries or rejects with an error. */ async getEntries(datatableName, entityId) { try { const apiPath = `/fineract-provider/api/v1/datatables/${datatableName}/${entityId}`; const response = await this.httpClient.get(apiPath); return response.data; } catch (rawError) { const errorPayload = rawError; const message = errorPayload?.message || errorPayload?.error || "Fineract API request failed"; throw new errors_1.FineractApiError(message, errorPayload?.statusCode, errorPayload?.details, errorPayload?.error); } } /** * Creates a new datatable entry for a specific entity. * Corresponds to the POST /datatables/{datatableName}/{entityId} endpoint. * * @param datatableName The name of the datatable. * @param entityId The id of the entity (e.g. m_client.id) to create the datatable entry for. * @param entryData The data for the new datatable entry. * @returns A promise that resolves to the creation response or rejects with an error. */ async createEntry(datatableName, entityId, entryData) { try { const apiPath = `/fineract-provider/api/v1/datatables/${datatableName}/${entityId}`; const response = await this.httpClient.post(apiPath, entryData); return response.data; } catch (rawError) { const errorPayload = rawError; const message = errorPayload?.message || errorPayload?.error || "Fineract API request failed"; throw new errors_1.FineractApiError(message, errorPayload?.statusCode, errorPayload?.details, errorPayload?.error); } } /** * Updates a datatable entry for a specific entity. * Corresponds to the PUT /datatables/{datatableName}/{entityId} endpoint. * * @param datatableName The name of the datatable. * @param entityId The id of the entity (e.g. m_client.id). * @param entryData The updated data for the datatable entry. * @returns A promise that resolves to the update response or rejects with an error. */ async updateEntry(datatableName, entityId, entryData) { try { const apiPath = `/fineract-provider/api/v1/datatables/${datatableName}/${entityId}`; const response = await this.httpClient.put(apiPath, entryData); return response.data; } catch (rawError) { const errorPayload = rawError; const message = errorPayload?.message || errorPayload?.error || "Fineract API request failed"; throw new errors_1.FineractApiError(message, errorPayload?.statusCode, errorPayload?.details, errorPayload?.error); } } /** * Deletes a datatable entry for a specific entity. * Corresponds to the DELETE /datatables/{datatableName}/{entityId} endpoint. * * @param datatableName The name of the datatable. * @param entityId The id of the entity (e.g. m_client.id). * @returns A promise that resolves to the deletion response or rejects with an error. */ async deleteEntry(datatableName, entityId) { try { const apiPath = `/fineract-provider/api/v1/datatables/${datatableName}/${entityId}`; const response = await this.httpClient.delete(apiPath); return response.data; } catch (rawError) { const errorPayload = rawError; const message = errorPayload?.message || errorPayload?.error || "Fineract API request failed"; throw new errors_1.FineractApiError(message, errorPayload?.statusCode, errorPayload?.details, errorPayload?.error); } } } exports.FineractDatatableApi = FineractDatatableApi; //# sourceMappingURL=fineract-datatable-api.js.map