first commit
This commit is contained in:
131
source/lib-inject.ts
Normal file
131
source/lib-inject.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
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,
|
||||
setupID: 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);
|
||||
logging.info(NAME_SPACE, "\t INFO Setup id: " + setupID);
|
||||
|
||||
try {
|
||||
const resp = await axios.post(
|
||||
url,
|
||||
{
|
||||
statusOutbox: statusOutbox,
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
setupID: setupID,
|
||||
},
|
||||
{
|
||||
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)
|
||||
);
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user