I am trying to have a conditional condition added to my Sequelize query so I can filter like below, but currently it doesn't work, because it overwrites $and.
How do I do it properly?
const params = {
where: {
$or:
sequelize.literal(
`exists (select 1 from "FootballGamePlayers" fp where fp.game_id = "FootballGame".id and fp.player_id = ${req.user_id})
OR
exists (select 1 from "FootballGameInvites" gi where gi.game_id = "FootballGame".id and gi.user_id = ${req.user_id})
`)
}
if (req.query.isActive === 'true') {
params.where = { ...params.where, $and: sequelize.literal('end_date > NOW()') }
} else if (req.query.isActive === 'false') {
params.where = { ...params.where, $and: sequelize.literal('end_date < NOW()') }
}
await FootballGames.findAndCountAll(params)