Reputation: 83
Can somebody help me to fix this my error, there's my code:
const { UserLogs } = require("../models");
let logscontroller = {};
logscontroller.getAll = (req, res) => {
console.log(req.body);
let search = req.body.search.value;
console.log(search);
if (search === "") {
UserLogs.findAll({
offset: req.body.start,
limit: req.body.length,
order: [["id", "ASC"]],
raw: true
})
.then(result => {
res.json({
data: result
});
})
.catch(err => {
console.log(err);
});
} else {
UserLogs.findAll({
where: {
email: {
$or: search
}
},
offset: req.body.start,
limit: req.body.length,
order: [["id", "ASC"]],
raw: true
})
.then(result => {
res.json({
data: result
});
})
.catch(err => {
console.log(err);
});
}
return;
};
logscontroller.index = (req, res) => {
res.render("logs", {
title: "Logs Users"
});
};
module.exports = logscontroller;
And There's My Error, I Don't know why..
TypeError: value.map is not a function at Object._whereBind (D:\HASH\back-office-2\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2180:21) at Object.whereItemQuery (D:\HASH\back-office-2\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2070:19) at Utils.getComplexKeys.forEach.prop (D:\HASH\back-office-2\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1957:25) at Array.forEach () at Object.whereItemsQuery (D:\HASH\back-office-2\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1955:35) at Object.getWhereConditions (D:\HASH\back-office-2\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2423:19) at Object.selectQuery (D:\HASH\back-office-2\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1133:28) at QueryInterface.select (D:\HASH\back-office-2\node_modules\sequelize\lib\query-interface.js:1077:27) at Promise.try.then.then.then (D:\HASH\back-office-2\node_modules\sequelize\lib\model.js:1596:34) at tryCatcher (D:\HASH\back-office-2\node_modules\bluebird\js\release\util.js:16:23) at Promise._settlePromiseFromHandler (D:\HASH\back-office-2\node_modules\bluebird\js\release\promise.js:512:31) at Promise._settlePromise (D:\HASH\back-office-2\node_modules\bluebird\js\release\promise.js:569:18) at Promise._settlePromise0 (D:\HASH\back-office-2\node_modules\bluebird\js\release\promise.js:614:10) at Promise._settlePromises (D:\HASH\back-office-2\node_modules\bluebird\js\release\promise.js:693:18) at Async._drainQueue (D:\HASH\back-office-2\node_modules\bluebird\js\release\async.js:133:16) at Async._drainQueues (D:\HASH\back-office-2\node_modules\bluebird\js\release\async.js:143:10) at Immediate.Async.drainQueues (D:\HASH\back-office-2\node_modules\bluebird\js\release\async.js:17:14) at runCallback (timers.js:789:20) at tryOnImmediate (timers.js:751:5) at processImmediate [as _immediateCallback] (timers.js:722:5)
Upvotes: 0
Views: 5668
Reputation: 58553
as per the Sequelize Doc , $or
accepts array:
$or : [{authorId: 12}, {authorId: 13}]
and this is what you have used
email: {
$or: search
}
I think what you need is :
email : search // for exact match
or
email : {
$ilke : `%${search}%` // for partial match
}
Upvotes: 0