Skip to content

Commit 31c0a79

Browse files
Kevin WangAwk34
Kevin Wang
authored andcommitted
fix(endpoint:controller): wrap saveUpdates in an if(entity) statement
fixes #2052, closes #2059
1 parent 1fbf24b commit 31c0a79

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Diff for: templates/endpoint/basename.controller.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ function respondWithResult(res, statusCode) {
2525

2626
function saveUpdates(updates) {
2727
return function(entity) {
28-
<% if (filters.mongooseModels) { %>var updated = _.merge(entity, updates);
29-
return updated.save()
30-
.then(updated => {<% }
31-
if (filters.sequelizeModels) { %>return entity.updateAttributes(updates)
32-
.then(updated => {<% } %>
33-
return updated;
34-
});
28+
if(entity) {
29+
<% if (filters.mongooseModels) { %>var updated = _.merge(entity, updates);
30+
return updated.save()
31+
.then(updated => {<% }
32+
if (filters.sequelizeModels) { %>return entity.updateAttributes(updates)
33+
.then(updated => {<% } %>
34+
return updated;
35+
});
36+
}
3537
};
3638
}
3739

0 commit comments

Comments
 (0)