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.
108 lines (107 loc) • 4.2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useIdentification = void 0;
const dataStructure_1 = __importDefault(require("../helper/dataStructure"));
const helper_1 = __importDefault(require("../helper"));
const restApi_1 = __importDefault(require("../restApi"));
const useIdentification = (token, userInfo, userId, baseUrl, geoCoordinates, lang) => {
const { checkResponse, headerConfig } = (0, helper_1.default)(userInfo);
const { checkGlobalResponse, errorHandler } = checkResponse();
const { dataIdentification } = (0, dataStructure_1.default)();
const { createDataIdentification, deleteDataIdentification, updateDataIdentification, } = dataIdentification();
let endPointIdentification = `v1/user/identification/${userId}`;
const headerConfigIdentification = () => {
let headersData = {
header: true,
isUrlEncoded: false,
token: token,
lang: lang,
};
let headers = headerConfig(headersData);
return headers;
};
const CreateIdentification = async (values) => {
let data = createDataIdentification({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", endPointIdentification, headerConfigIdentification(), data);
let { newUserInfo } = checkGlobalResponse("identification", response, "CreateIdentification", "create");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ??
"Identification Created Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const UpdateIdentification = async (values) => {
let data = updateDataIdentification({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "PUT", endPointIdentification, headerConfigIdentification(), data);
let { newUserInfo } = checkGlobalResponse("identification", response, "UpdateIdentification", "update");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ??
"Identification Updated Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const DeleteIdentification = async (values) => {
let data = deleteDataIdentification({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "DELETE", endPointIdentification, headerConfigIdentification(), data);
let { newUserInfo } = checkGlobalResponse("identification", response, "DeleteIdentification", "delete");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ??
"Identification Deleted Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
return {
CreateIdentification,
UpdateIdentification,
DeleteIdentification,
};
};
exports.useIdentification = useIdentification;