【发布时间】:2022-01-20 07:38:51
【问题描述】:
这是我的 API 代码。它运行良好,但缺少我的“startedDate”:“2022-01-01”,并且 "endDate":"2022-01-31" ...我如何编写函数请解决我的问题并分享你的想法..
async getcurrentmonthorder2(req, res, next) {
try {
const {startedDate ,endDate} = req.body;
db.product.findAll({
attributes:[[sequelize.fn('sum',sequelize.col('profit_total')),'total']],
where : {"createdAt" : {[Op.between] : [new Date(startedDate).setHours(0,0,0,0) , new Date(endDate).setHours(23,59,59,999) ]}},
})
.then(list => {
res.status(200).json({ 'success': true, data: list });
})
.catch(function (err) {
next(err)
});
}
catch (err) {
res.status(500).json({ 'errors': "" + err });
}
}
#我已经从邮递员那里得到了输出..
{
"success": true,
"data": [
{
"total": "121",
}
]
}
#but 我想要这个输出请帮忙分享你的想法
{
"success": true,
"data": [
{
"total": "121",
"startedDate":"2022-01-01",
"endDate":"2022-01-31"
}
]
}
我的数据
{id: 1, total: 20, profit_total: 15, createdAt: "2021-12-30T15:59:10.000Z",…}
【问题讨论】:
标签: node.js reactjs express sequelize.js