I have the following sequelize query:
let prms = periods.map((period, index, arr) => {
if (arr[index + 1]) {
return sequelize.models.Result.aggregate('value', 'avg', {
where: {
createdAt: {
$lt: arr[index + 1],
$gt: period
},
type: hook.params.headers.type,
entityId: hook.params.headers.entity
}
}).catch(err => console.log('err'));
}
})
Now, the createdAt
property on the where object is causing me this problem:
error: Error: Invalid value 1506211200000 at Object.escape (C:\Users\George\Source\Repos\myProj\node_modules\sequelize\lib\sql-string.js:50:11) at Object.escape (C:\Users\George\Source\Repos\myProj\node_modules\sequelize\lib\dialects\abstract\query-generator.js:917:22)
Now I don't have any idea where the 1506211200000
number is coming from, both arr[index + 1]
and period
are moment.js objects, and I can verify this by doing console.log(arr[index + 1].isValid(), period.isValid());
which prints true true
. If remove the createdAt restriction, there is no issue.
Any idea what is going on here?
NB: I am using Postgres