Ao utilizar o operador Op.gte ele captura normal, porém ao utilizar Op.lte ele me estoura a stack trace:
D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\api\controllers\TurmaController.js:11
data_final ? where.data_final[Op.lte] = data_final : null
^
TypeError: Cannot set properties of undefined (setting 'Symbol(lte)')
at pegaTodasAsTurmas (D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\api\controllers\TurmaController.js:11:43)
at Layer.handle [as handle_request] (D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\node_modules\express\lib\router\layer.js:95:5)
at next (D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\node_modules\express\lib\router\layer.js:95:5)
at D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\node_modules\express\lib\router\index.js:284:15
at Function.process_params (D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\node_modules\express\lib\router\index.js:346:12)
at next (D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\node_modules\express\lib\router\index.js:280:10)
at Function.handle (D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\node_modules\express\lib\router\index.js:175:3)
at router (D:\projetos\Alura\orm-nodejs-api-sequelize-mysql2\node_modules\express\lib\router\index.js:47:12)
meu controller:
static async pegaTodasAsTurmas(req, res){
const {data_inicial, data_final} = req.query
const where = {}
data_inicial || data_final ? where.data_inicial = {} : null
data_inicial ? where.data_inicial[Op.gte] = data_inicial : null
data_final ? where.data_final[Op.lte] = data_final : null
try {
const todasAsTurmas = await database.Turmas.findAll({ where })
return res.status(200).json(todasAsTurmas)
} catch (error) {
return res.status(500).json(error.message)
}
}
Repositorio: https://github.com/IgorMartinsOli/orm-nodejs-api-sequelize-mysql