low stock notification

This commit is contained in:
2ManyProjects 2025-04-28 14:10:49 -05:00
parent 9519442771
commit 4e0608ab9b
2 changed files with 4 additions and 5 deletions

View file

@ -819,6 +819,7 @@ module.exports = (pool, query, authMiddleware) => {
if (product.stock_notification) { if (product.stock_notification) {
try { try {
// If it's a string, parse it // If it's a string, parse it
// why are we doing this its been an obj for months now
if (typeof product.stock_notification === 'string') { if (typeof product.stock_notification === 'string') {
stockNotification = JSON.parse(product.stock_notification); stockNotification = JSON.parse(product.stock_notification);
} else { } else {

View file

@ -81,11 +81,9 @@ const notificationService = {
const transporter = this.createTransporter(); const transporter = this.createTransporter();
// Send notifications for each low stock product // Send notifications for each low stock product
console.log(JSON.stringify(lowStockProducts, null, 4))
for (const product of lowStockProducts.rows) { for (const product of lowStockProducts.rows) {
console.log(JSON.stringify(product, null, 4)) console.log("LOW STOCK ON: ", JSON.stringify(product, null, 4))
console.log(typeof product.stock_notification) const notification = product.stock_notification;
const notification = JSON.parse(product.stock_notification);
try { try {
// Send email notification // Send email notification
@ -139,7 +137,7 @@ const notificationService = {
* @returns {string} HTML email template * @returns {string} HTML email template
*/ */
generateLowStockEmailTemplate(product) { generateLowStockEmailTemplate(product) {
const stockNotification = JSON.parse(product.stock_notification); const stockNotification = product.stock_notification;
const threshold = stockNotification.threshold || 0; const threshold = stockNotification.threshold || 0;
return ` return `