Skip to content

Commit c262211

Browse files
committed
fix (endpoint:controller): fix findOneAndUpdate syntax
findOneAndUpdate return modified document now instead of original fixes angular-fullstack#2284
1 parent 89a43a4 commit c262211

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function upsert(req, res) {
101101
delete req.body._id;
102102
}
103103
<%_ if(filters.mongooseModels) { -%>
104-
return <%= classedName %>.findOneAndUpdate({_id: req.params.id}, req.body, {upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()<% } %>
104+
return <%= classedName %>.findOneAndUpdate({_id: req.params.id}, req.body, {new: true, upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()<% } %>
105105
<%_ if(filters.sequelizeModels) { -%>
106106
return <%= classedName %>.upsert(req.body, {
107107
where: {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ describe('<%= classedName %> API:', function() {
105105
updated<%= classedName %> = {};
106106
});
107107
108-
it('should respond with the original <%= cameledName %>', function() {
109-
<%= expect() %>updated<%= classedName %>.name<%= to() %>.equal('New <%= classedName %>');
110-
<%= expect() %>updated<%= classedName %>.info<%= to() %>.equal('This is the brand new <%= cameledName %>!!!');
108+
it('should respond with the updated <%= cameledName %>', function() {
109+
<%= expect() %>updated<%= classedName %>.name<%= to() %>.equal('Updated <%= classedName %>');
110+
<%= expect() %>updated<%= classedName %>.info<%= to() %>.equal('This is the updated <%= cameledName %>!!!');
111111
});
112112
113113
it('should respond with the updated <%= cameledName %> on a subsequent GET', function(done) {

0 commit comments

Comments
 (0)