Last active
August 21, 2021 15:05
-
-
Save ziglee/89b88ba6bf67c1a282805146c4d00f38 to your computer and use it in GitHub Desktop.
Listing all Costumers with birthday today or tomorrow using Sequelize.js.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/api/birthday', function (req, res, next) { | |
var month = moment().month() + 1; | |
var today = moment().date(); | |
var tomorrow = moment().add(1, 'days').date(); | |
Costumer.findAll({ | |
attributes: ['id','name','birthDate'], | |
where: { | |
$and: [ | |
sequelize.where(sequelize.fn('month', sequelize.col("birth_date")), month) | |
], | |
$or: [ | |
sequelize.where(sequelize.fn('day', sequelize.col("birth_date")), today), | |
sequelize.where(sequelize.fn('day', sequelize.col("birth_date")), tomorrow) | |
] | |
}, | |
order: [ | |
sequelize.fn('month', sequelize.col("birth_date")), | |
sequelize.fn('day', sequelize.col("birth_date")), | |
'name' | |
] | |
}).then(function (result) { | |
res.status(200).json(result); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment