Skip to content

Commit 17ba01b

Browse files
aniknafsAwk34
authored andcommitted
fix (endpoint:controller): fix findOneAndUpdate syntax (#2301)
findOneAndUpdate return modified document now instead of original fixes #2284
1 parent 73d15dd commit 17ba01b

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)