I am trying to run a put function to update a user in my mongoDB, but I am getting a 500 Internal Service error. I am using the angular-fullstack generator
I use this resource in my controller:
update(User) {
User.$update();
}
Here are the functions I call in the backend to try and put the data everything seems to be working fine except for when I call saveUpdates, it seems like that is triggering the 500 error.:
function handleError(res, statusCode) {
statusCode = statusCode || 500;
return function(err) {
res.status(statusCode).send(err);
};
}
// this seems to be the function giving me the problem.
function saveUpdates(updates) {
return function(entity) {
var updated = _.merge(entity, updates);
return updated.saveAsync()
.spread(updated => {
return updated;
});
};
}
function respondWithResult(res, statusCode) {
statusCode = statusCode || 200;
return function(entity) {
if (entity) {
res.status(statusCode).json(entity);
}
};
}
function handleEntityNotFound(res) {
return function(entity) {
if (!entity) {
res.status(404).end();
return null;
}
return entity;
};
}
export function updateUser(req, res) {
if (req.body._id) {
delete req.body._id;
}
User.findByIdAndUpdate(req.params.id)
.then(handleEntityNotFound(res))
.then(saveUpdates(req.body))
.then(respondWithResult(res))
.catch(handleError(res));
}
I have tried following recommendations on this page for angular-full stack, such as changing ._merge to ._extend to no avail.