I'm trying to get some subtotals using Sequelize, and this is how my query looks like.
const getAllCustomerEarnings = async (customerAccountId) => {
return await customerEarnings.findAll({
attributes: [
[Sequelize.fn('SUM', Sequelize.col('amount')), 'amount'],
[Sequelize.fn('date_trunc', 'day', Sequelize.col('createdAt')), 'createdAt'],
],
where: {
[Op.and]: [
{customerAccountId: customerAccountId},
]
},
order: [['createdAt', 'ASC']],
group: 'createdAt'
})
}
However, what I get as an output are not subtotals on per-day basis. I actually get each and every record from the table, with time part set to 00:00:000Z
What should I change in order to get subtotals for each day?