Reputation: 2381
I'm new using Sequelize and Node.js, but I have issue with date comparison in my code.
User.findOne({ where: {
resetToken: passwordToken,
resetTokenExpiration: { $gt: Date.now() },
id: userId
}})
When I run it and check the log, the query is:
SELECT `id`, `password`, `email`, `resetToken`, `resetTokenExpiration`, `createdAt`, `updatedAt` FROM `users` AS `user` WHERE `user`.`resetToken` = 'f5779192069c3f1c3d8aae3019cf6172e83d9f07b3741a50caedf793dc3bb43c' AND `user`.`resetTokenExpiration` = '2019-11-19 06:00:00' LIMIT 1;
Why is it not using resetTokenExpiration > date, but resetTokenExpiration = date?
Thanks
Upvotes: 0
Views: 267
Reputation: 18909
You need to specify the correct range operators which is [Op.gt]
in this case.
User.findOne({ where: {
resetToken: passwordToken,
resetTokenExpiration: { [Op.gt]: Date.now() }
id: userId
}})
Upvotes: 2