I want deliveredAmount and ordersAmount group it by month, does anybody have a solution?, I thought maybe a if statement. Or maybe a group by month but that is only for the SQL and this is API
//Count specific values from database
const ordersAmount = await Order.count();
const deliverdAmount = await Order.count({
where: {
status: "DELIVERED",
},
});
orders.forEach((order) => {
//converteer het gewicht van elke order naar de beste maat
let value = convert(order.weight).from("g").toBest();
order.weight = `${Math.round(value.val)} ${value.unit}`;
// Format the created_at date
order.date = moment(order.created_at).format("YYYY-MM-DD");
});
// Render the page, pass on the order array
res.render(req.user.role === "COURIER" ?
"dashboard/courier/overview" :
"dashboard/overview", {
title: "Overzicht - Dashboard",
orders,
sort: req.sort,
order: req.order,
limit: req.limit,
user: req.user,
search: req.search,
page: req.page,
ordersAmount,
deliverdAmount,
}
);