@crediblex.io/fineract-api-client
Version:
TypeScript client for Fineract APIs
141 lines • 6.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FineractSavingsAccountsApi = void 0;
const errors_1 = require("../types/errors");
/**
* API client for Fineract Savings Accounts related operations.
* It uses the HttpClient for making requests.
*/
class FineractSavingsAccountsApi {
constructor(httpClient) {
this.httpClient = httpClient;
}
/**
* Retrieves all savings accounts from Fineract.
* Corresponds to the GET /savingsaccounts endpoint.
*
* @returns A promise that resolves to the list of savings accounts or rejects with an error.
*/
async getAll() {
try {
const apiPath = "/fineract-provider/api/v1/savingsaccounts";
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 account by ID from Fineract.
* Corresponds to the GET /savingsaccounts/{accountId} endpoint.
*
* @param accountId The ID of the savings account to retrieve.
* @returns A promise that resolves to the savings account details or rejects with an error.
*/
async getById(accountId) {
try {
const apiPath = `/fineract-provider/api/v1/savingsaccounts/${accountId}`;
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 account in Fineract.
* Corresponds to the POST /savingsaccounts endpoint.
*
* @param accountData The data for the new savings account.
* @returns A promise that resolves to the creation response or rejects with an error.
*/
async create(accountData) {
try {
const apiPath = "/fineract-provider/api/v1/savingsaccounts";
const response = await this.httpClient.post(apiPath, accountData);
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 account from Fineract.
* Corresponds to the DELETE /savingsaccounts/{accountId} endpoint.
*
* @param accountId The ID of the savings account to delete.
* @returns A promise that resolves to the deletion response or rejects with an error.
*/
async delete(accountId) {
try {
const apiPath = `/fineract-provider/api/v1/savingsaccounts/${accountId}`;
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);
}
}
/**
* Creates a deposit transaction for a savings account in Fineract.
* Corresponds to the POST /savingsaccounts/{accountId}/transactions?command=deposit endpoint.
*
* @param accountId The ID of the savings account to deposit into.
* @param transactionData The data for the deposit transaction.
* @returns A promise that resolves to the deposit transaction response or rejects with an error.
*/
async deposit(accountId, transactionData) {
try {
const apiPath = `/fineract-provider/api/v1/savingsaccounts/${accountId}/transactions?command=deposit`;
const response = await this.httpClient.post(apiPath, transactionData);
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 the transaction template for a savings account in Fineract.
* Corresponds to the GET /savingsaccounts/{accountId}/transactions/template endpoint.
*
* @param accountId The ID of the savings account to get the transaction template for.
* @returns A promise that resolves to the transaction template response or rejects with an error.
*/
async getTransactionTemplate(accountId) {
try {
const apiPath = `/fineract-provider/api/v1/savingsaccounts/${accountId}/transactions/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.FineractSavingsAccountsApi = FineractSavingsAccountsApi;
//# sourceMappingURL=fineract-savingsaccounts-api.js.map