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.

110 lines (109 loc) 4.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useBlockchain = void 0; const restApi_1 = __importDefault(require("../restApi")); const helper_1 = __importDefault(require("../helper")); const dataStructure_1 = __importDefault(require("../helper/dataStructure")); const constants_1 = require("../constants"); const blockchainHelper_1 = require("../utils/blockchainHelper"); const useBlockchain = (token, userInfo, userId, baseUrl, lang) => { const { checkResponse, headerConfig } = (0, helper_1.default)(userInfo); const { checkGlobalResponse } = checkResponse(); const { GetBlockchainRequestData } = (0, dataStructure_1.default)(); const GetHeadersConfig = () => { return headerConfig({ header: true, isUrlEncoded: false, token, lang, }); }; const RequestHandler = async (data, requestType) => { try { const endpoint = (0, blockchainHelper_1.GetEndpointByRequestType)(requestType); const response = await restApi_1.default.restApi(baseUrl, constants_1.HTTPMethod.POST, endpoint, GetHeadersConfig(), data); const { key, functionName } = (0, blockchainHelper_1.GetKeyAndFunctionNameByRequestType)(requestType); const { newUserInfo } = checkGlobalResponse(key, response, functionName, key); return { response: response?.data, newUser: newUserInfo, message: response?.data?.result?.message ?? "Operation Completed Successfully", status: "success", }; } catch (error) { return { response: error.response?.data, newUser: null, message: error.message, status: "failed", }; } }; const SendRequest = async (values) => { try { const data = GetBlockchainRequestData(values, constants_1.BlockchainRequestType.Send); return await RequestHandler(data, constants_1.BlockchainRequestType.Send); } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const MultiSendRequest = async (values) => { try { const data = GetBlockchainRequestData(values, constants_1.BlockchainRequestType.Multi_Send); return await RequestHandler(data, constants_1.BlockchainRequestType.Multi_Send); } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const DelegateRequest = async (values) => { try { const data = GetBlockchainRequestData(values, constants_1.BlockchainRequestType.Delegate); return await RequestHandler(data, constants_1.BlockchainRequestType.Delegate); } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const UndelegateRequest = async (values) => { try { const data = GetBlockchainRequestData(values, constants_1.BlockchainRequestType.Undelegate); return await RequestHandler(data, constants_1.BlockchainRequestType.Undelegate); } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; return { SendRequest, MultiSendRequest, DelegateRequest, UndelegateRequest, }; }; exports.useBlockchain = useBlockchain;