0

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,
    }
);
MORÈ
  • 1,834
  • 1
  • 11
  • 20
  • 1
    Does this answer your question? [Most efficient method to groupby on an array of objects](https://stackoverflow.com/questions/14446511/most-efficient-method-to-groupby-on-an-array-of-objects) – Peter B May 08 '22 at 09:34

0 Answers0