Help solve the problem. The table contains the fields price and quantity. One of the filtering parameters in the request comes the cost. How to correctly and beautifully write filtering by the cost parameter using Sequilize:
const DESC = query.desc ? 'DESC' : 'ASC';
const where = {
...(query.square_from && {
square_feet: {
[Op.gte]: query.square_from,
},
}),
...(query.square_to && {
square_feet: {
[Op.lte]: query.square_to,
},
}),
//??????????????????????????????????????????????????????????
...(query.total_price_from &&
Sequelize.where(Sequelize.literal('token_price*lot_size'), {
[Op.gte]: query.total_price_from,
})),
//?????????????????????????????????????????????????????????
};
return await this.propertySchema.findAndCountAll({
where,
attributes: { exclude: ['createdAt', 'updatedAt'] },
order: [[query.orderby, DESC]],
limit: PROPERTIES_BY_PAGE,
offset: +(query.page - 1) * PROPERTIES_BY_PAGE,
distinct: true,
include: [
{
model: Files,
attributes: { exclude: ['createdAt', 'updatedAt'] },
through: {
attributes: ['is_main'],
},
},
],
});
}
}