This is one thing that really annoys me! I have to write 2 different functions for almost the same query!
Say I\'ve got an API that returns posts that a
posts
i had some similar situation , and i used template literals to define empty string as default if the field was undefined.
User.findOne({ where: { [Op.or]: [ { email: `${req.body.email || ""}` }, { username: `${req.body.username || ""}` }, ], },
})