@crediblex.io/fineract-api-client
Version:
TypeScript client for Fineract APIs
184 lines • 7.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FineractSavingsProductsApi = void 0;
const errors_1 = require("../types/errors");
/**
* API client for Fineract Savings Products related operations.
* It uses the HttpClient for making requests.
*/
class FineractSavingsProductsApi {
constructor(httpClient) {
this.httpClient = httpClient;
}
/**
* Retrieves all savings products from Fineract.
* Corresponds to the GET /savingsproducts endpoint.
*
* @returns A promise that resolves to the list of savings products or rejects with an error.
*/
async getAll() {
try {
const apiPath = "/fineract-provider/api/v1/savingsproducts";
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 savings product by ID from Fineract.
* Corresponds to the GET /savingsproducts/{productId} endpoint.
*
* @param productId The ID of the savings product to retrieve.
* @returns A promise that resolves to the savings product details or rejects with an error.
*/
async getById(productId) {
try {
const apiPath = `/fineract-provider/api/v1/savingsproducts/${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 savings product in Fineract.
* Corresponds to the POST /savingsproducts endpoint.
*
* @param productData The data for the new savings 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/savingsproducts";
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 savings product in Fineract.
* Corresponds to the PUT /savingsproducts/{productId} endpoint.
*
* @param productId The ID of the savings product to update.
* @param productData The updated data for the savings 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/savingsproducts/${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 savings product from Fineract.
* Corresponds to the DELETE /savingsproducts/{productId} endpoint.
*
* @param productId The ID of the savings 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/savingsproducts/${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 savings product.
* Corresponds to the GET /savingsproducts/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/savingsproducts/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);
}
}
/**
* Approves a savings account.
* Corresponds to the POST /savingsaccounts/{accountId}?command=approve endpoint.
*
* @param accountId The ID of the savings account to approve.
* @param approvalData The data for the approval, including the approval date.
* @returns A promise that resolves to the approval response or rejects with an error.
*/
async approve(accountId, approvalData) {
try {
const apiPath = `/fineract-provider/api/v1/savingsaccounts/${accountId}?command=approve`;
const response = await this.httpClient.post(apiPath, approvalData);
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);
}
}
/**
* Activates a savings account.
* Corresponds to the POST /savingsaccounts/{accountId}?command=activate endpoint.
*
* @param accountId The ID of the savings account to activate.
* @param activationData The data for the activation, including the activation date.
* @returns A promise that resolves to the activation response or rejects with an error.
*/
async activate(accountId, activationData) {
try {
const apiPath = `/fineract-provider/api/v1/savingsaccounts/${accountId}?command=activate`;
const response = await this.httpClient.post(apiPath, activationData);
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.FineractSavingsProductsApi = FineractSavingsProductsApi;
//# sourceMappingURL=fineract-savingsproducts-api.js.map