Untitled
unknown
plain_text
2 years ago
1.7 kB
8
Indexable
const calculateDaysLeft = (platform, endDate) => {
const todayDate = new Date(todayDateFormatted());
const lastDayDate = new Date(endDate);
const timeDifference = lastDayDate - todayDate;
return Math.ceil(timeDifference / (1000 * 60 * 60 * 24));
};
const processDomainMessages = (sendableDomainArray) => {
const messages = {
5: 'Reminder: (5) Day left till platform shutdown',
3: 'Reminder: (3) Day left till platform shutdown',
1: 'Reminder: (1) Day left till platform shutdown',
'-1': 'Reminder: (1) Days ago platform shut down',
'-2': 'Reminder: (2) Days ago platform shut down',
};
return sendableDomainArray
.filter(item => messages[calculateDaysLeft(item.domain, item.endDate)])
.map(item => ({ 'domain': item.domain, 'message': messages[calculateDaysLeft(item.domain, item.endDate)] }));
};
const updatePaymentMessages = async () => {
try {
const domains = await controllers.readDomainsFile(filePath);
const sendableDomains = domains
.filter(item => item.paidAt && item.paidAt.trim() !== "")
.map(item => ({ 'domain': item.domain, 'endDate': item.paidAt.split('|')[1] }));
const pipelineResult = processDomainMessages(sendableDomains);
// Update existing domains array directly
domains.forEach(item => {
const sendableItem = pipelineResult.find(sendable => sendable.domain === item.domain);
if (sendableItem) {
item.message = sendableItem.message;
}
});
console.info('Updated payment records');
await controllers.writeDomainsFile(filePath, domains);
} catch (error) {
console.error('Error updating payment records:', error.message);
}
};
Editor is loading...
Leave a Comment