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.

140 lines (139 loc) 5.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useAccount = void 0; const restApi_1 = __importDefault(require("../restApi")); const helper_1 = __importDefault(require("../helper")); const dataStructure_1 = __importDefault(require("../helper/dataStructure")); const useAccount = (token, userInfo, userId, baseUrl, geoCoordinates, lang) => { const { checkResponse, headerConfig } = (0, helper_1.default)(userInfo); const { checkGlobalResponse } = checkResponse(); const { dataAccount } = (0, dataStructure_1.default)(); const { dataDoTransaction, paramGetTransaction } = dataAccount(); const endPointTransaction = `v1/transaction`; const endPointUserAccounts = `v1/user/account/${userId}`; const endPointAccount = "v1/account"; const headerConfigAccount = (installationId) => { let headersData = { header: true, isUrlEncoded: false, token: token, lang: lang, installationId: installationId, }; let headers = headerConfig(headersData); return headers; }; const GetTransactionByUserId = async (values) => { let params = paramGetTransaction({ ...values, geoCoordinates: geoCoordinates }, userId); try { const response = await restApi_1.default.restApi(baseUrl, "GET", `${endPointTransaction}/inquiry`, headerConfigAccount(), null, params); let { newUserInfo } = checkGlobalResponse("account", response, "getTransaction", "get"); return { response: response, newUser: newUserInfo, message: response?.data?.result?.message ?? "Get Transaction Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const GetUserAccounts = async (installationId) => { try { const response = await restApi_1.default.restApi(baseUrl, "GET", endPointUserAccounts, headerConfigAccount(installationId)); let { newUserInfo } = checkGlobalResponse("account", response, "getAccount", "getAccount"); return { response: response?.data?.account, newUser: newUserInfo, message: response?.data?.result?.message ?? "Get Account Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const GetAccountData = async (accountId) => { try { const response = await restApi_1.default.restApi(baseUrl, "GET", `${endPointAccount}/${accountId}`, headerConfigAccount()); let { newUserInfo } = checkGlobalResponse("account", response, "getAccount", "getAccount"); return { response: response?.data?.account, newUser: newUserInfo, message: response?.data?.result?.message ?? "Get Account Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const DoTransaction = async (values) => { let data = dataDoTransaction({ ...values, geoCoordinates: geoCoordinates }); try { const response = await restApi_1.default.restApi(baseUrl, "POST", `${endPointTransaction}`, headerConfigAccount(), data); let { newUserInfo } = checkGlobalResponse("account", response, "doTransaction", "doTransaction"); return { response: response?.data, newUser: newUserInfo, message: response?.data?.result?.message ?? "Transaction Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const GetAccountLimit = async (values) => { try { const response = await restApi_1.default.restApi(baseUrl, "GET", `v1/account/${values.account_id}`, headerConfigAccount()); let { newUserInfo } = checkGlobalResponse("account", response, "getAccountLimit", "getAccountLimit"); return { response: response?.data, newUser: newUserInfo, message: response?.data?.result?.message ?? "Get Account Limit Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; return { GetTransactionByUserId, GetUserAccounts, GetAccountData, DoTransaction, GetAccountLimit, }; }; exports.useAccount = useAccount;