new feat: gateway dipakai bersama dengan send-wa-kwitansi
including:
- remove batch_size di config-gw-wa.json
- merge function, bedakan dengan message_type
This commit is contained in:
@@ -3,47 +3,46 @@ import config from "./config/config";
|
||||
import logging from "./config/logging";
|
||||
import { NAME_SPACE } from "./server";
|
||||
|
||||
type MessageType = "mcu" | "payment";
|
||||
|
||||
export const getListOutbox = async (
|
||||
messageType: MessageType,
|
||||
statusOutbox: string,
|
||||
startDate: string,
|
||||
endDate: string
|
||||
) => {
|
||||
const url = config.base_url + "mockup/sendwa/sendwa/listoutbox";
|
||||
logging.info(NAME_SPACE, "\t INFO : " + url);
|
||||
const url =
|
||||
config.base_url + config.messageTypes[messageType].endpoints.listOutbox;
|
||||
logging.info(
|
||||
NAME_SPACE,
|
||||
`\t INFO [${config.messageTypes[messageType].name}]: ${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,
|
||||
},
|
||||
{ statusOutbox, startDate, 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;
|
||||
return typeof resp.data === "string"
|
||||
? JSON.parse(resp.data)
|
||||
: resp.data;
|
||||
} 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);
|
||||
}
|
||||
handleAxiosError(e, messageType);
|
||||
}
|
||||
};
|
||||
|
||||
export const sendToQontak = async (param: any) => {
|
||||
const url = config.base_url + "mockup/sendwa/sendwa/QontakSendMsg";
|
||||
logging.info(NAME_SPACE, "\t INFO : " + url);
|
||||
export const sendToQontak = async (messageType: MessageType, param: any) => {
|
||||
const url =
|
||||
config.base_url + config.messageTypes[messageType].endpoints.sendMsg;
|
||||
logging.info(
|
||||
NAME_SPACE,
|
||||
`\t INFO [${config.messageTypes[messageType].name}]: ${url}`
|
||||
);
|
||||
logging.info(NAME_SPACE, "\t INFO Payload: " + JSON.stringify(param));
|
||||
|
||||
try {
|
||||
@@ -55,29 +54,31 @@ export const sendToQontak = async (param: any) => {
|
||||
|
||||
logging.info(
|
||||
NAME_SPACE,
|
||||
"\t INFO Resp Qontak: " + JSON.stringify(statusResp)
|
||||
`\t INFO Resp [${
|
||||
config.messageTypes[messageType].name
|
||||
}]: ${JSON.stringify(statusResp)}`
|
||||
);
|
||||
if (statusResp != "OK") {
|
||||
logging.error(
|
||||
NAME_SPACE,
|
||||
"\t Error Qontak: " + JSON.stringify(resp.data)
|
||||
`\t Error [${
|
||||
config.messageTypes[messageType].name
|
||||
}]: ${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);
|
||||
}
|
||||
handleAxiosError(e, messageType);
|
||||
}
|
||||
};
|
||||
|
||||
export const uploadFileCdn = async (param: any) => {
|
||||
const url = config.base_url + "mockup/sendwa/sendwa/uploadfile";
|
||||
logging.info(NAME_SPACE, "\t INFO : " + url);
|
||||
export const uploadFileCdn = async (messageType: MessageType, param: any) => {
|
||||
const url =
|
||||
config.base_url + config.messageTypes[messageType].endpoints.uploadFile;
|
||||
logging.info(
|
||||
NAME_SPACE,
|
||||
`\t INFO [${config.messageTypes[messageType].name}]: ${url}`
|
||||
);
|
||||
logging.info(NAME_SPACE, "\t INFO Payload: " + JSON.stringify(param));
|
||||
|
||||
try {
|
||||
@@ -85,28 +86,31 @@ export const uploadFileCdn = async (param: any) => {
|
||||
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)
|
||||
`\t INFO Resp Upload [${
|
||||
config.messageTypes[messageType].name
|
||||
}]: ${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);
|
||||
}
|
||||
handleAxiosError(e, messageType);
|
||||
}
|
||||
};
|
||||
|
||||
export const changeStatusOutbox = async (param: any) => {
|
||||
const url = config.base_url + "mockup/sendwa/sendwa/changeStatusOutbox";
|
||||
logging.info(NAME_SPACE, "\t INFO : " + url);
|
||||
export const changeStatusOutbox = async (
|
||||
messageType: MessageType,
|
||||
param: any
|
||||
) => {
|
||||
const url =
|
||||
config.base_url +
|
||||
config.messageTypes[messageType].endpoints.changeStatus;
|
||||
logging.info(
|
||||
NAME_SPACE,
|
||||
`\t INFO [${config.messageTypes[messageType].name}]: ${url}`
|
||||
);
|
||||
logging.info(NAME_SPACE, "\t INFO Payload: " + JSON.stringify(param));
|
||||
|
||||
try {
|
||||
@@ -114,21 +118,31 @@ export const changeStatusOutbox = async (param: any) => {
|
||||
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)
|
||||
`\t INFO Resp Change Status [${
|
||||
config.messageTypes[messageType].name
|
||||
}]: ${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);
|
||||
}
|
||||
handleAxiosError(e, messageType);
|
||||
}
|
||||
};
|
||||
|
||||
function handleAxiosError(e: any, messageType: MessageType) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
logging.error(
|
||||
NAME_SPACE,
|
||||
`Error [${config.messageTypes[messageType].name}] - Axios Error`
|
||||
);
|
||||
logging.error(NAME_SPACE, e.response?.data?.toString());
|
||||
} else if (e instanceof Error) {
|
||||
logging.error(
|
||||
NAME_SPACE,
|
||||
`Error [${config.messageTypes[messageType].name}] - ${e.message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user