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.

87 lines (86 loc) 3.32 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.usePersonalInfo = void 0; const dataStructure_1 = __importDefault(require("../helper/dataStructure")); const helper_1 = __importDefault(require("../helper")); const restApi_1 = __importDefault(require("../restApi")); const usePersonalInfo = (token, userInfo, userId, baseUrl, geoCoordinates, lang) => { const { dataPersonalInfo } = (0, dataStructure_1.default)(); const { updateDataPersonalInfo, updateProfilePicture } = dataPersonalInfo(); const { checkResponse, headerConfig } = (0, helper_1.default)(userInfo); const { checkGlobalResponse, errorHandler } = checkResponse(); let endPoint = `v1/user/personal_info/${userId}`; const headerConfigPersonalInfo = () => { let headersData = { header: true, isUrlEncoded: false, token: token, lang: lang, }; let headers = headerConfig(headersData); return headers; }; const UpdatePersonalInfo = async (values) => { const data = updateDataPersonalInfo({ ...values, geoCoordinates: geoCoordinates, }); try { const response = await restApi_1.default.restApi(baseUrl, "PUT", endPoint, headerConfigPersonalInfo(), data); let { newUserInfo } = checkGlobalResponse("personal_info", response, "UpdatePersonalInfo", "updateObjectInfo"); return { response: response, newUser: newUserInfo, message: response?.data?.result?.message ?? "User Info updated Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; const UpdateProfilePicture = async (values) => { const data = updateProfilePicture({ ...values, geoCoordinates: geoCoordinates, }); let headersData = { header: true, isUrlEncoded: false, token: values.token ?? token, lang: lang, }; let headers = headerConfig(headersData); try { const response = await restApi_1.default.restApi(baseUrl, "POST", `V1/User/document/${values.userId ?? userId}`, headers, data); let { newUserInfo } = checkGlobalResponse("personal_info", response, "UpdateProfilePicture", "updateProfilePicture"); return { response: response, newUser: newUserInfo, message: response?.data?.result?.message ?? "Picture Updated Successfully", status: "success", }; } catch (error) { return { response: error.response, newUser: null, message: error.message, status: "failed", }; } }; return { UpdatePersonalInfo, UpdateProfilePicture, }; }; exports.usePersonalInfo = usePersonalInfo;