135 lines
4.5 KiB
TypeScript
135 lines
4.5 KiB
TypeScript
import axios from "axios";
|
|
import config from "./config/config";
|
|
import logging from "./config/logging";
|
|
import { NAME_SPACE } from "./server";
|
|
|
|
export const getListOutbox = async (
|
|
statusOutbox: string,
|
|
startDate: string,
|
|
endDate: string
|
|
) => {
|
|
const url = config.base_url + "mockup/sendwa/sendwa/listoutbox";
|
|
logging.info(NAME_SPACE, "\t INFO : " + url);
|
|
logging.info(NAME_SPACE, "\t INFO Status Outbox: " + statusOutbox);
|
|
logging.info(NAME_SPACE, "\t INFO Start Date: " + startDate);
|
|
logging.info(NAME_SPACE, "\t INFO End Date: " + endDate);
|
|
|
|
try {
|
|
const resp = await axios.post(
|
|
url,
|
|
{
|
|
statusOutbox: statusOutbox,
|
|
startDate: startDate,
|
|
endDate: endDate,
|
|
},
|
|
{
|
|
headers: { "Content-Type": "application/json; charset=UTF-8" },
|
|
responseType: "text",
|
|
}
|
|
);
|
|
const jresp =
|
|
typeof resp.data === "string" ? JSON.parse(resp.data) : resp.data;
|
|
return jresp;
|
|
} catch (e) {
|
|
if (axios.isAxiosError(e)) {
|
|
logging.error(NAME_SPACE, "Error di lib inject catch axios");
|
|
logging.error(NAME_SPACE, e.response?.data.toString());
|
|
} else if (e instanceof Error) {
|
|
logging.error(NAME_SPACE, "Error di instance of error");
|
|
logging.error(NAME_SPACE, e.message);
|
|
}
|
|
}
|
|
};
|
|
|
|
export const sendToQontak = async (param: any) => {
|
|
const url = config.base_url + "mockup/sendwa/sendwa/QontakSendMsg";
|
|
logging.info(NAME_SPACE, "\t INFO : " + url);
|
|
logging.info(NAME_SPACE, "\t INFO Payload: " + JSON.stringify(param));
|
|
|
|
try {
|
|
const resp = await axios.post(url, param, {
|
|
headers: { "Content-Type": "application/json; charset=UTF-8" },
|
|
responseType: "text",
|
|
});
|
|
const statusResp = resp.data.status;
|
|
|
|
logging.info(
|
|
NAME_SPACE,
|
|
"\t INFO Resp Qontak: " + JSON.stringify(statusResp)
|
|
);
|
|
if (statusResp != "OK") {
|
|
logging.error(
|
|
NAME_SPACE,
|
|
"\t Error Qontak: " + JSON.stringify(resp.data)
|
|
);
|
|
}
|
|
return statusResp;
|
|
} catch (e) {
|
|
if (axios.isAxiosError(e)) {
|
|
logging.error(NAME_SPACE, "Error di lib inject catch axios");
|
|
logging.error(NAME_SPACE, e.response?.data.toString());
|
|
} else if (e instanceof Error) {
|
|
logging.error(NAME_SPACE, "Error di instance of error");
|
|
logging.error(NAME_SPACE, e.message);
|
|
}
|
|
}
|
|
};
|
|
|
|
export const uploadFileCdn = async (param: any) => {
|
|
const url = config.base_url + "mockup/sendwa/sendwa/uploadfile";
|
|
logging.info(NAME_SPACE, "\t INFO : " + url);
|
|
logging.info(NAME_SPACE, "\t INFO Payload: " + JSON.stringify(param));
|
|
|
|
try {
|
|
const resp = await axios.post(url, param, {
|
|
headers: { "Content-Type": "application/json; charset=UTF-8" },
|
|
responseType: "text",
|
|
});
|
|
|
|
const statusResp = resp.data.status;
|
|
|
|
logging.info(
|
|
NAME_SPACE,
|
|
"\t INFO Resp Upload: " + JSON.stringify(statusResp)
|
|
);
|
|
return statusResp;
|
|
} catch (e) {
|
|
if (axios.isAxiosError(e)) {
|
|
logging.error(NAME_SPACE, "Error di lib inject catch axios");
|
|
logging.error(NAME_SPACE, e.response?.data.toString());
|
|
} else if (e instanceof Error) {
|
|
logging.error(NAME_SPACE, "Error di instance of error");
|
|
logging.error(NAME_SPACE, e.message);
|
|
}
|
|
}
|
|
};
|
|
|
|
export const changeStatusOutbox = async (param: any) => {
|
|
const url = config.base_url + "mockup/sendwa/sendwa/changeStatusOutbox";
|
|
logging.info(NAME_SPACE, "\t INFO : " + url);
|
|
logging.info(NAME_SPACE, "\t INFO Payload: " + JSON.stringify(param));
|
|
|
|
try {
|
|
const resp = await axios.post(url, param, {
|
|
headers: { "Content-Type": "application/json; charset=UTF-8" },
|
|
responseType: "text",
|
|
});
|
|
|
|
const statusResp = resp.data.status;
|
|
|
|
logging.info(
|
|
NAME_SPACE,
|
|
"\t INFO Resp Change Status: " + JSON.stringify(statusResp)
|
|
);
|
|
return statusResp;
|
|
} catch (e) {
|
|
if (axios.isAxiosError(e)) {
|
|
logging.error(NAME_SPACE, "Error di lib inject catch axios");
|
|
logging.error(NAME_SPACE, e.response?.data.toString());
|
|
} else if (e instanceof Error) {
|
|
logging.error(NAME_SPACE, "Error di instance of error");
|
|
logging.error(NAME_SPACE, e.message);
|
|
}
|
|
}
|
|
};
|