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.
198 lines (197 loc) • 7.89 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDevice = void 0;
const restApi_1 = __importDefault(require("../restApi"));
const helper_1 = __importDefault(require("../helper"));
const dataStructure_1 = __importDefault(require("../helper/dataStructure"));
const useDevice = (token, userInfo, userId, baseUrl, lang, geoCoordinates) => {
const { checkResponse, headerConfig } = (0, helper_1.default)(userInfo);
const { checkGlobalResponse } = checkResponse();
const { dataDevice } = (0, dataStructure_1.default)();
const { dataCreateDevice, dataUpdateDevice, dataDeleteDevice, dataVerifyDevice, dataConfirmDevice, dataLogoutDevice, } = dataDevice();
let endPointDevice = `v1/user/device/${userId}`;
const headerConfigDevice = () => {
let headersData = {
header: true,
isUrlEncoded: false,
token: token,
lang: lang,
};
let headers = headerConfig(headersData);
return headers;
};
const CreateDevice = async (values, access_token, user_id) => {
let data = dataCreateDevice({ ...values, geoCoordinates: geoCoordinates });
let headersData = {
header: true,
isUrlEncoded: false,
token: access_token ? access_token : token,
lang: lang,
};
let headers = headerConfig(headersData);
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/device/${user_id ? user_id : userId}`, headers, data);
let { newUserInfo } = checkGlobalResponse("device", response, "CreateDevice", "create");
return {
response: response?.data,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Create Device Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const UpdateDevice = async (values, access_token, user_id) => {
let data = dataUpdateDevice({ ...values, geoCoordinates: geoCoordinates });
let headersData = {
header: true,
isUrlEncoded: false,
token: access_token ? access_token : token,
lang: lang,
};
let headers = headerConfig(headersData);
try {
const response = await restApi_1.default.restApi(baseUrl, "PUT", `v1/user/device/${user_id ? user_id : userId}`, headers, data);
let { newUserInfo } = checkGlobalResponse("device", response, "UpdateDevice", "update");
return {
response: response?.data,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Update Device Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const DeleteDevice = async (values) => {
let data = dataDeleteDevice({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "DELETE", `${endPointDevice}`, headerConfigDevice(), data);
let { newUserInfo } = checkGlobalResponse("device", response, "DeleteDevice", "delete");
return {
response: response?.data,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Delete Device Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const VerifyDevice = async (values) => {
let data = dataVerifyDevice({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/verify/${userId}`, headerConfigDevice(), data);
let { newUserInfo } = checkGlobalResponse("device", response, "VerifyDevice", "verify");
return {
response: response?.data,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Verify Device Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const ConfirmDevice = async (values) => {
let data = dataConfirmDevice({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/confirm/${userId}`, headerConfigDevice(), data);
let { newUserInfo } = checkGlobalResponse("device", response, "ConfirmDevice", "confirm");
return {
response: response?.data,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Confirm Device Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const GetUserDeviceLoginHistory = async () => {
try {
const response = await restApi_1.default.restApi(baseUrl, "GET", `v1/user/device/history/${userId}`, headerConfigDevice());
let { newUserInfo } = checkGlobalResponse("device", response, "GetUserDeviceLoginHistory", "GetUserDeviceLoginHistory");
return {
response: response?.data,
newUser: newUserInfo,
message: response?.data?.result?.message ??
"Get User Device Login History Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const LogoutDevice = async (values) => {
let data = dataLogoutDevice({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "PUT", `v1/user/device/logout/${userId}`, headerConfigDevice(), data);
let { newUserInfo } = checkGlobalResponse("device", response, "LogoutDevice", "update");
return {
response: response?.data,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Logout Device Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
return {
CreateDevice,
UpdateDevice,
DeleteDevice,
VerifyDevice,
ConfirmDevice,
GetUserDeviceLoginHistory,
LogoutDevice,
};
};
exports.useDevice = useDevice;