I want to use async and await to handle the promises. I would like to use this on the given example below:
exports.getUserData = async function(userId){
let query = {};
if(userId){
query.where = {userid : req.query.id}
}
let data;
try{
data = await entity.DB_User.findAll(query);
}catch(error){
console.log(error);
}
}
On execution its giving me an error
Error:
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
userId
to the function and not passing it to where the query if(userId){ query.where = {userid : req.query.id} // userId instead of req.query.id ? } – Aditya Kokil