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.
165 lines (164 loc) • 6.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePhone = void 0;
const dataStructure_1 = __importDefault(require("../helper/dataStructure"));
const helper_1 = __importDefault(require("../helper"));
const restApi_1 = __importDefault(require("../restApi"));
const usePhone = (token, userInfo, userId, baseUrl, geoCoordinates, lang) => {
const { checkResponse, headerConfig } = (0, helper_1.default)(userInfo);
const { checkGlobalResponse, errorHandler } = checkResponse();
const { dataPhone } = (0, dataStructure_1.default)();
const { confirmDataPhone, createDataPhone, deleteDataPhone, makePrimaryDataPhone, updateDataPhone, verifyDataPhone, } = dataPhone();
let endPointPhone = `v1/user/phone/${userId}`;
const headerConfigPhone = () => {
let headersData = {
header: true,
isUrlEncoded: false,
token: token,
lang: lang,
};
let headers = headerConfig(headersData);
return headers;
};
const CreateUserPhone = async (values) => {
let data = createDataPhone({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", endPointPhone, headerConfigPhone(), data);
let { newUserInfo } = checkGlobalResponse("phone", response, "CreateUserPhone", "create");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Phone Created Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const DeleteUserPhone = async (values) => {
let data = deleteDataPhone({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "DELETE", endPointPhone, headerConfigPhone(), data);
let { newUserInfo } = checkGlobalResponse("phone", response, "DeleteUserPhone", "delete");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Phone Deleted Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const VerifyUserPhone = async (values) => {
let data = verifyDataPhone({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/verify/${userId}`, headerConfigPhone(), data);
let { newUserInfo } = checkGlobalResponse("phone", response, "VerifyUserPhone");
return {
response: response,
newUser: newUserInfo,
message: "Verification Code Message Sent Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const ConfirmUserPhone = async (values) => {
let data = confirmDataPhone({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/confirm/${userId}`, headerConfigPhone(), data);
let { newUserInfo } = checkGlobalResponse("phone", response, "ConfirmUserPhone", "confirm");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Phone Confirmed Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const UpdateUserPhone = async (values) => {
let data = updateDataPhone({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "PUT", endPointPhone, headerConfigPhone(), data);
let { newUserInfo } = checkGlobalResponse("phone", response, "UpdateUserPhone", "update");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Phone Updated Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const MakeUserPhonePrimary = async (values) => {
let data = makePrimaryDataPhone({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "PUT", endPointPhone, headerConfigPhone(), data);
let { newUserInfo } = checkGlobalResponse("phone", response, "MakeUserPhonePrimary", "updatePrimary");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? `${values.number} Now Is Primary`,
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
return {
CreateUserPhone,
DeleteUserPhone,
VerifyUserPhone,
ConfirmUserPhone,
UpdateUserPhone,
MakeUserPhonePrimary,
};
};
exports.usePhone = usePhone;