You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letbaseQuery="SELECT clients.user_email, clients.name, MIN(invoices.date) AS oldest_invoice_date, MAX(total_amount) AS most_expensive_invoice_total FROM clients LEFT JOIN (\
18
20
SELECT invoices.client_email, invoices.id, SUM((invoices_products.unit_price * invoices_products.quantity) * (1 - (invoices.discount / 100))) AS total_amount FROM invoices\
19
21
LEFT JOIN invoices_products ON invoices.id = invoices_products.invoice_id GROUP BY invoices.id ) AS invoice_totals ON clients.user_email = invoice_totals.client_email LEFT JOIN\
20
22
invoices ON invoice_totals.id = invoices.id GROUP BY clients.user_email";
letdateDif=newDate(Date.now()-(row.oldest_invoice_date==null ? Date.now() : row.oldest_invoice_date.getTime())).getUTCFullYear()-1970;//restamos la unix timestamp de hoy y la de la fecha de la compra mas vieja. Eso nos da la diferencia de años + 1970
38
+
letdateDif=newDate(Date.now()-(row['oldest_invoice_date']==null ? Date.now() : row['oldest_invoice_date'].getTime())).getUTCFullYear()-1970;//restamos la unix timestamp de hoy y la de la fecha de la compra mas vieja. Eso nos da la diferencia de años + 1970
42
39
43
40
if(dateDif>=3)
44
41
allowedDiscount=30;
45
42
46
43
clients.push({
47
-
email : row.user_email,
48
-
name : row.name,
44
+
email : row['user_email'],
45
+
name : row['name'],
49
46
allowedDiscount : allowedDiscount
50
47
});
51
48
});
@@ -55,7 +52,7 @@ SELECT invoices.client_email, invoices.id, SUM((invoices_products.unit_price * i
55
52
console.log(error);
56
53
res.status(500).send({error:"Internal Server Error"});
0 commit comments