low stock notification
This commit is contained in:
parent
9519442771
commit
4e0608ab9b
2 changed files with 4 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 `
|
||||
|
|
|
|||
Loading…
Reference in a new issue