[api, actions] logActions, TLogEvent 추가

This commit is contained in:
younghoon100.park
2024-04-25 17:09:53 +09:00
parent daa03e4a65
commit 523d9df071
2 changed files with 246 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
import axios from "axios";
import { getUrl, URLS } from "./apiConfig";
import { clearLaunchParams, getLaunchParams } from "../utils/helperMethods";
import { createQueryString } from "../utils/helperMethods";
export const TLogEvent = (
dispatch,
getState,
type,
baseUrl,
urlParams = {},
params = {},
onSuccess,
onFail
) => {
const httpHeader = getState().common.httpHeader;
const appStatus = getState().common.appStatus;
const AUTHORIZATION = { headers: { ...httpHeader } };
const { cntry_cd: cntryCd, plat_cd: platCd, prod_cd: prodCd } = httpHeader;
const { deviceId: dvcId } = appStatus;
const dvcTp = "tv";
if (typeof window === "object") {
let url = Array.isArray(baseUrl)
? getUrl(getState, baseUrl[0])
: getUrl(getState, baseUrl);
if (!url) {
return;
}
// pyh 수정
if (type === "get") {
const _urlparams = createQueryString(urlParams);
url += _urlparams ? `?${_urlparams}` : "";
}
let linkTpCd = "";
// pyh 수정
if (httpHeader) {
const launchParams = getLaunchParams();
if (launchParams?.contentTarget) {
const tokens = launchParams.contentTarget.split("_");
if (tokens[0] === "V3") {
linkTpCd = tokens[1];
}
}
}
const model = {
...params,
adId: "",
cntryCd,
dvcId,
dvcTp,
linkTpCd,
platCd,
prodCd,
};
let axiosInstance;
switch (type) {
case "get":
axiosInstance = axios.get(url, AUTHORIZATION);
break;
case "post":
axiosInstance = axios.post(url, model, AUTHORIZATION);
break;
}
if (axiosInstance) {
axiosInstance
.then((res) => {
if (onSuccess) {
onSuccess(res);
}
})
.catch((error) => {
if (onFail) {
onFail(error);
}
});
// .finally(clearLaunchParams);
}
}
};