improve pushover notification service

This commit is contained in:
weakmap@gmail.com
2025-01-10 19:51:14 +01:00
parent 97deea6f5b
commit 8fe7cec2a1
3 changed files with 70 additions and 45 deletions

View File

@@ -7,9 +7,11 @@ export const send = ({ serviceName, newListings, notificationConfig, jobKey }) =
const job = getJob(jobKey);
const jobName = job == null ? jobKey : job.name;
const promises = newListings.map((newListing) => {
const message = `Address: ${newListing.address} Size: ${newListing.size.replace(/2m/g, '$m^2$')} Price: ${
newListing.price
}`;
const message = `
Address: ${newListing.address}
Size: ${newListing.size.replace(/2m/g, '$m^2$')}
Price: ${newListing.price}
Link: ${newListing.link}`;
return fetch(server, {
method: 'POST',
body: JSON.stringify({

View File

@@ -22,7 +22,30 @@ export const send = ({ serviceName, newListings, notificationConfig, jobKey }) =
});
});
return Promise.all(promises);
return Promise.all(promises)
.then((responses) => {
// Convert all responses to JSON
return Promise.all(responses.map((response) => response.json()));
})
.then((data) => {
// Check for errors in the data
const error = data
.map((item) => (item.errors != null && item.errors.length > 0 ? item.errors.join(', ') : null))
.filter((err) => err !== null);
if (error.length > 0) {
// Reject with the combined error messages
return Promise.reject(error.join('; '));
}
return data;
})
.then(() => {
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
};
export const config = {

View File

@@ -1,6 +1,6 @@
{
"name": "fredy",
"version": "11.0.1",
"version": "11.0.2",
"description": "[F]ind [R]eal [E]states [d]amn eas[y].",
"scripts": {
"start": "node prod.js",