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.
162 lines (161 loc) • 6.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useEmail = void 0;
const dataStructure_1 = __importDefault(require("../helper/dataStructure"));
const helper_1 = __importDefault(require("../helper"));
const restApi_1 = __importDefault(require("../restApi"));
const useEmail = (token, userInfo, userId, baseUrl, geoCoordinates, lang) => {
let endPointEmail = `v1/user/email/${userId}`;
const { checkResponse, headerConfig } = (0, helper_1.default)(userInfo);
const { checkGlobalResponse } = checkResponse();
const { dataEmail } = (0, dataStructure_1.default)();
const { confirmDataEmail, createDataEmail, deleteDataEmail, primaryDataEmail, updateDataEmail, verifyDataEmail, } = dataEmail();
const headerConfigEmail = () => {
let headersData = {
header: true,
isUrlEncoded: false,
token: token,
lang: lang,
};
let headers = headerConfig(headersData);
return headers;
};
const CreateUserEmail = async (values) => {
let data = createDataEmail({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", endPointEmail, headerConfigEmail(), data);
let { newUserInfo } = checkGlobalResponse("email", response, "CreateUserEmail", "create");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Email Created Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const DeleteUserEmail = async (values) => {
let data = deleteDataEmail({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "DELETE", endPointEmail, headerConfigEmail(), data);
let { newUserInfo } = checkGlobalResponse("email", response, "DeleteUserEmail", "delete");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Email Deleted Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const VerifyUserEmail = async (values) => {
let data = verifyDataEmail({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/verify/${userId}`, headerConfigEmail(), data);
let { newUserInfo } = checkGlobalResponse("email", response, "VerifyUserEmail");
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 ConfirmUserEmail = async (values) => {
let data = confirmDataEmail({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/confirm/${userId}`, headerConfigEmail(), data);
let { newUserInfo } = checkGlobalResponse("email", response, "ConfirmUserEmail", "confirm");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Email Confirmed Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const UpdateUserEmail = async (values) => {
let data = updateDataEmail({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "PUT", endPointEmail, headerConfigEmail(), data);
let { newUserInfo } = checkGlobalResponse("email", response, "UpdateUserEmail", "update");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Email Updated Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const MakeUserEmailPrimary = async (values) => {
let data = primaryDataEmail({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "PUT", endPointEmail, headerConfigEmail(), data);
let { newUserInfo } = checkGlobalResponse("email", response, "MakeUserEmailPrimary", "updatePrimary");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? `${values.address} Now Is Primary`,
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
return {
CreateUserEmail,
DeleteUserEmail,
VerifyUserEmail,
ConfirmUserEmail,
UpdateUserEmail,
MakeUserEmailPrimary,
};
};
exports.useEmail = useEmail;