fix minor bugs
parent
ff32be3368
commit
344776f864
|
@ -133,6 +133,39 @@ const emailUtils = require("./email-utils");
|
||||||
`processed/`
|
`processed/`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capture response
|
||||||
|
*/
|
||||||
|
const checkShippingLabelResponse = async (page, timer) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// Timeout mechanism to resolve with an empty list after 5 seconds
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
page.off("response", handleResponse); // Remove listener on timeout
|
||||||
|
resolve([]); // Resolve with an empty list
|
||||||
|
}, timer);
|
||||||
|
|
||||||
|
const handleResponse = async (res) => {
|
||||||
|
try {
|
||||||
|
const req = res.request();
|
||||||
|
if (req.url().includes("/batch_print_shipping_label")) {
|
||||||
|
const resJson = await res.json();
|
||||||
|
// Remove listener and clear timeout once response is captured
|
||||||
|
clearTimeout(timeout);
|
||||||
|
page.off("response", handleResponse);
|
||||||
|
resolve(resJson || []);
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
// Remove listener and clear timeout on error
|
||||||
|
clearTimeout(timeout);
|
||||||
|
page.off("response", handleResponse);
|
||||||
|
reject(ex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
page.on("response", handleResponse);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
||||||
// set the pagination to 100 / page
|
// set the pagination to 100 / page
|
||||||
|
@ -150,38 +183,6 @@ const emailUtils = require("./email-utils");
|
||||||
await page.click(pagesPerPageSelector);
|
await page.click(pagesPerPageSelector);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1_000));
|
await new Promise((resolve) => setTimeout(resolve, 1_000));
|
||||||
|
|
||||||
/**
|
|
||||||
* Capture response
|
|
||||||
*/
|
|
||||||
const checkShippingLabelResponse = async (page, timer) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
// Timeout mechanism to resolve with an empty list after 5 seconds
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
page.off("response", handleResponse); // Remove listener on timeout
|
|
||||||
resolve([]); // Resolve with an empty list
|
|
||||||
}, timer);
|
|
||||||
|
|
||||||
const handleResponse = async (res) => {
|
|
||||||
try {
|
|
||||||
const req = res.request();
|
|
||||||
if (req.url().includes("/batch_print_shipping_label")) {
|
|
||||||
const resJson = await res.json();
|
|
||||||
// Remove listener and clear timeout once response is captured
|
|
||||||
clearTimeout(timeout);
|
|
||||||
page.off("response", handleResponse);
|
|
||||||
resolve(resJson || []);
|
|
||||||
}
|
|
||||||
} catch (ex) {
|
|
||||||
// Remove listener and clear timeout on error
|
|
||||||
clearTimeout(timeout);
|
|
||||||
page.off("response", handleResponse);
|
|
||||||
reject(ex);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
page.on("response", handleResponse);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emailUtils.notify(`Download Order Shipping Labels`, e.message);
|
emailUtils.notify(`Download Order Shipping Labels`, e.message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ const transporter = nodemailer.createTransport({
|
||||||
// send email using transporter send to multiple tos
|
// send email using transporter send to multiple tos
|
||||||
const notify = (subject, body) => {
|
const notify = (subject, body) => {
|
||||||
// params
|
// params
|
||||||
let recipients = ["saif.haq@utopia.pk", "huzaifa.jiwani@utopia.pk"];
|
let recipients = ["saif.haq@utopia.pk"];
|
||||||
let emailSubject = `Utopia Deals Temu FBU ${subject} Job`;
|
let emailSubject = `Utopia Deals Temu FBU ${subject} Job`;
|
||||||
let emailBody = `<p>${body}</p>`;
|
let emailBody = `<p>${body}</p>`;
|
||||||
|
|
||||||
|
@ -39,4 +39,4 @@ const notify = (subject, body) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
//export send email function
|
//export send email function
|
||||||
exports.notify = notify;
|
exports.notify = notify;
|
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
"last_updated": "2025-01-27T13:48:11.009+05:00",
|
|
||||||
"last_page": 1
|
|
||||||
}
|
|
Loading…
Reference in New Issue