I encountered an error stating: uncaughtException TypeError: cb is not a function I suspect that this error is related to a callback issue, but I am unsure of the root cause.
app.put('/badge/student_badge/:id', upload, (req, res, next) => {
const name = req.body.name;
let data = {
name: name
}
badger.updatePersonBadge({
id: req.params.id
}, data, (err) => {
if (err) return next(err);
res.status(201).json({
message: 'Post updated successfully!'
});
});
});
function updatePersonBadge(options, cb) {
schemas.badger.then(b => {
b.findById({
_id: options.id
}, (err, resp) => {
if (err) return cb(err);
if (!resp) return cb("no badge found");
name = options.name;
title = resp.title;
points = resp.points;
updateBadge(name, title, points, cb);
cb(null, resp);
})
})
}
function updateBadge(name, title, points, cb) {
const dateCreated = new Date(),
dateUpdated = dateCreated;
registerSchemas.personModel.then(p => {
p.findOneAndUpdate({
name: name
}, {
$push: {
badges: [{
title: title,
points: points,
dateCreated: dateCreated,
dateUpdated: dateUpdated
}]
}
}, (err, resp) => {
if (err) return cb(err);
if (!resp) return cb("no person found");
})
})
}