From 4e0608ab9bd4b0e7826922e0e4e43d8d73889414 Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Mon, 28 Apr 2025 14:10:49 -0500 Subject: [PATCH] low stock notification --- backend/src/routes/cart.js | 1 + backend/src/services/notificationService.js | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/src/routes/cart.js b/backend/src/routes/cart.js index d0d5f42..6e5f028 100644 --- a/backend/src/routes/cart.js +++ b/backend/src/routes/cart.js @@ -819,6 +819,7 @@ module.exports = (pool, query, authMiddleware) => { if (product.stock_notification) { try { // 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') { stockNotification = JSON.parse(product.stock_notification); } else { diff --git a/backend/src/services/notificationService.js b/backend/src/services/notificationService.js index 6311ba3..d2685aa 100644 --- a/backend/src/services/notificationService.js +++ b/backend/src/services/notificationService.js @@ -81,11 +81,9 @@ const notificationService = { const transporter = this.createTransporter(); // Send notifications for each low stock product - console.log(JSON.stringify(lowStockProducts, null, 4)) for (const product of lowStockProducts.rows) { - console.log(JSON.stringify(product, null, 4)) - console.log(typeof product.stock_notification) - const notification = JSON.parse(product.stock_notification); + console.log("LOW STOCK ON: ", JSON.stringify(product, null, 4)) + const notification = product.stock_notification; try { // Send email notification @@ -139,7 +137,7 @@ const notificationService = { * @returns {string} HTML email template */ generateLowStockEmailTemplate(product) { - const stockNotification = JSON.parse(product.stock_notification); + const stockNotification = product.stock_notification; const threshold = stockNotification.threshold || 0; return `