UNPKG

veend-sdk

Version:

a nodejs package for veend products

215 lines (214 loc) 10.6 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PrimeService = void 0; const endpoints_1 = require("./endpoints"); class PrimeService { constructor(apiClient, account, user) { this.apiClient = apiClient; this.account = account; } lendLoan(payload) { return __awaiter(this, void 0, void 0, function* () { try { let _q = this.apiClient.buildQuery({ accountId: this.account }); const response = yield this.apiClient.patch("lending", endpoints_1.PRIME_ENDPOINTS.lendLoan + _q, payload); return response; } catch (error) { throw new Error("Failed to lend loan: " + error.message); } }); } getLoanStatistics() { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.apiClient.get("lending", endpoints_1.PRIME_ENDPOINTS.loanStatistics); return response; } catch (error) { throw new Error("Failed to get loan statistics: " + error.message); } }); } getLoans(payload) { return __awaiter(this, void 0, void 0, function* () { try { let _q = this.apiClient.buildQuery({ accountId: this.account, populate: payload === null || payload === void 0 ? void 0 : payload.populate, desc: payload === null || payload === void 0 ? void 0 : payload.desc, sort: payload === null || payload === void 0 ? void 0 : payload.sort, limit: (payload === null || payload === void 0 ? void 0 : payload.limit) || 10, }); const response = yield this.apiClient.get("lending", endpoints_1.PRIME_ENDPOINTS.loans + _q); return response; } catch (error) { throw new Error("Failed to get loans: " + error.message); } }); } getLoanDetail(loanId, payload) { return __awaiter(this, void 0, void 0, function* () { try { let _q = this.apiClient.buildQuery({ accountId: this.account, populate: payload === null || payload === void 0 ? void 0 : payload.populate, }); const endpoint = endpoints_1.PRIME_ENDPOINTS.loanDetail.replace("{loanId}", loanId); const response = yield this.apiClient.get("lending", endpoint + _q); return response; } catch (error) { throw new Error("Failed to get loan details: " + error.message); } }); } getLoanRepaymentSchedule(loanId, payload) { return __awaiter(this, void 0, void 0, function* () { try { let _q = this.apiClient.buildQuery({ accountId: this.account, populate: payload === null || payload === void 0 ? void 0 : payload.populate, }); const endpoint = endpoints_1.PRIME_ENDPOINTS.loanRepaymentSchedule.replace("{loanId}", loanId); const response = yield this.apiClient.get("lending", endpoint + _q); return response; } catch (error) { throw new Error("Failed to get loan repayment schedule: " + error.message); } }); } getCustomers(payload) { return __awaiter(this, void 0, void 0, function* () { try { let _q = this.apiClient.buildQuery({ accountId: this.account, limit: (payload === null || payload === void 0 ? void 0 : payload.limit) || 10, page: payload === null || payload === void 0 ? void 0 : payload.page, populate: payload === null || payload === void 0 ? void 0 : payload.populate, desc: payload === null || payload === void 0 ? void 0 : payload.desc, sort: payload === null || payload === void 0 ? void 0 : payload.sort, }); const response = yield this.apiClient.get("lending", endpoints_1.PRIME_ENDPOINTS.customers + _q); return response; } catch (error) { throw new Error("Failed to get customers: " + error.message); } }); } SwitchPrimeRapaymentToBusinessAccount(enabled) { return __awaiter(this, void 0, void 0, function* () { try { const payload = { enabled }; const response = yield this.apiClient.patch("lending", endpoints_1.PRIME_ENDPOINTS.switchPrimeRapaymentToBusinessAccount, payload); return response; } catch (error) { throw new Error(`Failed to toggle business feature: ${error.message}`); } }); } updateIsBusinessFeature(enabled) { return __awaiter(this, void 0, void 0, function* () { try { const payload = { enabled }; const response = yield this.apiClient.patch("lending", endpoints_1.PRIME_ENDPOINTS.isBusinessFeature, payload); return response; } catch (error) { throw new Error(`Failed to toggle business feature: ${error.message}`); } }); } getLendingAccountHistory(payload) { return __awaiter(this, void 0, void 0, function* () { try { let _q = this.apiClient.buildQuery({ accountId: this.account, account: payload === null || payload === void 0 ? void 0 : payload.account, populate: payload === null || payload === void 0 ? void 0 : payload.populate, desc: payload === null || payload === void 0 ? void 0 : payload.desc, sort: payload === null || payload === void 0 ? void 0 : payload.sort, limit: (payload === null || payload === void 0 ? void 0 : payload.limit) || 10, }); const response = yield this.apiClient.get("giro", endpoints_1.PRIME_ENDPOINTS.lendingAccountHistory + _q); return response; } catch (error) { throw new Error("Failed to get lending account history: " + error.message); } }); } getLoanRepaymentHistory(payload) { return __awaiter(this, void 0, void 0, function* () { try { let _q = this.apiClient.buildQuery({ accountId: this.account, account: payload === null || payload === void 0 ? void 0 : payload.account, populate: payload === null || payload === void 0 ? void 0 : payload.populate, desc: payload === null || payload === void 0 ? void 0 : payload.desc, sort: payload === null || payload === void 0 ? void 0 : payload.sort, limit: (payload === null || payload === void 0 ? void 0 : payload.limit) || 10, repayment: payload === null || payload === void 0 ? void 0 : payload.repayment, onlender: payload === null || payload === void 0 ? void 0 : payload.onlender, }); const response = yield this.apiClient.get("giro", endpoints_1.PRIME_ENDPOINTS.loanRepaymentHistory + _q); return response; } catch (error) { throw new Error("Failed to get loan repayment history: " + error.message); } }); } getLendingAccountStatement(payload) { return __awaiter(this, void 0, void 0, function* () { try { let _q = this.apiClient.buildQuery({ accountId: this.account, account: payload === null || payload === void 0 ? void 0 : payload.account, populate: payload === null || payload === void 0 ? void 0 : payload.populate, desc: payload === null || payload === void 0 ? void 0 : payload.desc, sort: payload === null || payload === void 0 ? void 0 : payload.sort, limit: (payload === null || payload === void 0 ? void 0 : payload.limit) || 10, }); const response = yield this.apiClient.get("giro", endpoints_1.PRIME_ENDPOINTS.lendingAccountStatement + _q); return response; } catch (error) { throw new Error("Failed to get lending account statement: " + error.message); } }); } getBusinessAccountStatement(payload) { return __awaiter(this, void 0, void 0, function* () { try { let _q = this.apiClient.buildQuery({ accountId: this.account, account: payload === null || payload === void 0 ? void 0 : payload.account, populate: payload === null || payload === void 0 ? void 0 : payload.populate, desc: payload === null || payload === void 0 ? void 0 : payload.desc, sort: payload === null || payload === void 0 ? void 0 : payload.sort, limit: payload === null || payload === void 0 ? void 0 : payload.limit, }); const response = yield this.apiClient.get("giro", endpoints_1.PRIME_ENDPOINTS.businessAccountStatement + _q); return response; } catch (error) { throw new Error("Failed to get business account history: " + error.message); } }); } } exports.PrimeService = PrimeService;