UNPKG

ggez-banking-sdk

Version:

A Node.js package to handle GGEZ Banking API endpoints, Simplify the process of managing CRUD operations with this efficient and easy-to-use package.

123 lines (122 loc) 4.87 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useBankAccount = void 0; const dataStructure_1 = __importDefault(require("../helper/dataStructure")); const restApi_1 = __importDefault(require("../restApi")); const helper_1 = __importDefault(require("../helper")); const useBankAccount = (token, userInfo, userId, baseUrl, geoCoordinates, lang) => { const { dataBank } = (0, dataStructure_1.default)(); const { createDataBank, deleteDataBank, primaryDataBank, updateDataBank } = dataBank(); const { checkResponse, headerConfig } = (0, helper_1.default)(userInfo); const { checkGlobalResponse } = checkResponse(); let endPointBank = `v1/user/bank_account/${userId}`; const headerConfigBankAccount = () => { let headersData = { header: true, isUrlEncoded: false, token: token, lang: lang, }; let headers = headerConfig(headersData); return headers; }; // BankAccount const CreateBankAccount = async (values) => { let data = createDataBank({ ...values, geoCoordinates: geoCoordinates }); try { const response = await restApi_1.default.restApi(baseUrl, "POST", endPointBank, headerConfigBankAccount(), data); let { newUserInfo } = checkGlobalResponse("bank_account", response, "CreateBankAccount", "create"); return { response: response, newUser: newUserInfo, message: response?.data?.result?.message ?? "Bank Account Created Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const UpdateBankAccount = async (values) => { let data = updateDataBank({ ...values, geoCoordinates: geoCoordinates }); try { const response = await restApi_1.default.restApi(baseUrl, "PUT", endPointBank, headerConfigBankAccount(), data); let { newUserInfo } = checkGlobalResponse("bank_account", response, "UpdateBankAccount", "update"); return { response: response, newUser: newUserInfo, message: response?.data?.result?.message ?? "Bank Account Updated Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const MakeBankAccountPrimary = async (values) => { let data = primaryDataBank({ ...values, geoCoordinates: geoCoordinates }); try { const response = await restApi_1.default.restApi(baseUrl, "PUT", endPointBank, headerConfigBankAccount(), data); let { newUserInfo } = checkGlobalResponse("bank_account", response, "UpdateBankAccount", "updatePrimary"); return { response: response, newUser: newUserInfo, message: response?.data?.result?.message ?? "Primary Bank Account Updated Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const DeleteBankAccount = async (values) => { let data = deleteDataBank({ ...values, geoCoordinates: geoCoordinates }); try { const response = await restApi_1.default.restApi(baseUrl, "DELETE", endPointBank, headerConfigBankAccount(), data); let { newUserInfo } = checkGlobalResponse("bank_account", response, "DeleteBankAccount", "delete"); return { response: response, newUser: newUserInfo, message: response?.data?.result?.message ?? "Bank Account Deleted Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; return { CreateBankAccount, MakeBankAccountPrimary, UpdateBankAccount, DeleteBankAccount, }; }; exports.useBankAccount = useBankAccount;