@crediblex.io/fineract-api-client
Version:
TypeScript client for Fineract APIs
57 lines • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FineractHolidaysApi = void 0;
const errors_1 = require("../types/errors");
/**
* API client for Fineract Holidays related operations.
* It uses the HttpClient for making requests.
*/
class FineractHolidaysApi {
constructor(httpClient) {
this.httpClient = httpClient;
}
/**
* Retrieves holidays from Fineract.
* Corresponds to the GET /holidays endpoint.
* Only returns holidays with status.code === "holidayStatusType.active"
*
* @param params Optional parameters for filtering holidays.
* @returns A promise that resolves to the list of active holidays or rejects with an error.
*/
async getHolidays(params) {
try {
let apiPath = "/fineract-provider/api/v1/holidays";
// Add query parameters if provided
if (params?.officeId) {
apiPath += `?officeId=${params.officeId}`;
}
else {
apiPath += `?officeId=1`; // to ensure valid URL if no params
}
const response = await this.httpClient.get(apiPath);
// Filter to only return active holidays
const activeHolidays = response.data.filter((holiday) => holiday.status.code === "holidayStatusType.active");
return activeHolidays;
}
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 holidays for a specific office from Fineract.
* This is a convenience method that wraps getHolidays with officeId parameter.
* Only returns holidays with status.code === "holidayStatusType.active"
*
* @param officeId The ID of the office to get holidays for.
* @returns A promise that resolves to the list of active holidays for the specified office or rejects with an error.
*/
async getHolidaysByOffice(officeId) {
return this.getHolidays({ officeId });
}
}
exports.FineractHolidaysApi = FineractHolidaysApi;
//# sourceMappingURL=fineract-holidays-api.js.map