UNPKG

@crediblex.io/fineract-api-client

Version:
140 lines 5.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FineractLoanProductsApi = void 0; const errors_1 = require("../types/errors"); /** * API client for Fineract Loan Products related operations. * It uses the HttpClient for making requests. */ class FineractLoanProductsApi { constructor(httpClient) { this.httpClient = httpClient; } /** * Retrieves all loan products from Fineract. * Corresponds to the GET /loanproducts endpoint. * * @returns A promise that resolves to the list of loan products or rejects with an error. */ async getAll() { try { const apiPath = "/fineract-provider/api/v1/loanproducts"; 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 loan product by ID from Fineract. * Corresponds to the GET /loanproducts/{productId} endpoint. * * @param productId The ID of the loan product to retrieve. * @returns A promise that resolves to the loan product details or rejects with an error. */ async getById(productId) { try { const apiPath = `/fineract-provider/api/v1/loanproducts/${productId}`; 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 loan product in Fineract. * Corresponds to the POST /loanproducts endpoint. * * @param productData The data for the new loan product. * @returns A promise that resolves to the creation response or rejects with an error. */ async create(productData) { try { const apiPath = "/fineract-provider/api/v1/loanproducts"; const response = await this.httpClient.post(apiPath, productData); 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 an existing loan product in Fineract. * Corresponds to the PUT /loanproducts/{productId} endpoint. * * @param productId The ID of the loan product to update. * @param productData The updated data for the loan product. * @returns A promise that resolves to the update response or rejects with an error. */ async update(productId, productData) { try { const apiPath = `/fineract-provider/api/v1/loanproducts/${productId}`; const response = await this.httpClient.put(apiPath, productData); 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 loan product from Fineract. * Corresponds to the DELETE /loanproducts/{productId} endpoint. * * @param productId The ID of the loan product to delete. * @returns A promise that resolves to the deletion response or rejects with an error. */ async delete(productId) { try { const apiPath = `/fineract-provider/api/v1/loanproducts/${productId}`; 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); } } /** * Retrieves template data for creating a new loan product. * Corresponds to the GET /loanproducts/template endpoint. * * @returns A promise that resolves to the template data or rejects with an error. */ async getTemplate() { try { const apiPath = "/fineract-provider/api/v1/loanproducts/template"; 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); } } } exports.FineractLoanProductsApi = FineractLoanProductsApi; //# sourceMappingURL=fineract-loanproducts-api.js.map