Skip to content

Commit 21d8c7c

Browse files
committed
fixed updateMany bug on sql models
1 parent 7f7763b commit 21d8c7c

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
|:------|:------:|:------
44
| app.js | 61 | Write a complete Documentation for this project
55
| config/index.js | 12 | Test for production and development senarios
6+
| models/Testthrees.js | 95 | Test transactions
67
| models/index.js | 14 | Automatically generate tests with the schema structure
78
| routes/index.js | 260 | Test API versioning
89
| routes/index.js | 261 | Test rate limiting

services/queue/jobs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs.updateRequestLog = function(response, done){
3232
delete response.requestId;
3333
}
3434

35-
models.RequestLogs.updateMany({RequestId: requestId},response)
35+
models.RequestLogs.update({RequestId: requestId},response)
3636
.then(function(res){
3737
return done(false, res);
3838
})
@@ -92,12 +92,12 @@ split = _.flattenDeep(split);
9292
var task;
9393
if(model){
9494
if(isSQL){
95-
task = models[model].updateMany({ tags: split.join(', ')}, {where: dataClone} );
95+
task = models[model].update({ tags: split.join(', ')}, {where: dataClone} );
9696
}else{
9797
if(update){
98-
task = models[model].updateMany(dataClone,{ updatedAt: new Date(Date.now()).toISOString(), tags: split});
98+
task = models[model].update(dataClone,{ updatedAt: new Date(Date.now()).toISOString(), tags: split});
9999
}else{
100-
task = models[model].updateMany(dataClone,{ tags: split});
100+
task = models[model].update(dataClone,{ tags: split});
101101
}
102102
}
103103

services/request/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = function(service, requestId, uri, method, data, headers){
5454
return request(options);
5555
})
5656
.then(function(resp){
57-
return [Model.updateMany({RequestId: requestId, service: service}, {response: resp, responseStatusCode: 200, updatedAt: Date.now()}), resp];
57+
return [Model.update({RequestId: requestId, service: service}, {response: resp, responseStatusCode: 200, updatedAt: Date.now()}), resp];
5858
})
5959
.spread(function(update, resp){
6060
return resolve(resp);
@@ -65,7 +65,7 @@ module.exports = function(service, requestId, uri, method, data, headers){
6565
}else{
6666
var updateddd;
6767
if(existss){
68-
updateddd = Model.updateMany({RequestId: requestId, service: service}, {response: (err.response && err.response.body) ? err.response.body : { type: 'internal error', message: err.message}, responseStatusCode: err.statusCode ? err.statusCode : 500, updatedAt: Date.now()});
68+
updateddd = Model.update({RequestId: requestId, service: service}, {response: (err.response && err.response.body) ? err.response.body : { type: 'internal error', message: err.message}, responseStatusCode: err.statusCode ? err.statusCode : 500, updatedAt: Date.now()});
6969
}else{
7070
options.RequestId = requestId;
7171
options.service = service;

template/controller_sql.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ var <%= service %>sController = {};
139139
_query.limit = limit;
140140
}
141141
_query.where = query;
142-
var totalResult = <%= service %>s.estimatedDocumentCount(_query);
143-
var total = <%= service %>s.estimatedDocumentCount({});
142+
var totalResult = <%= service %>s.count(_query);
143+
var total = <%= service %>s.count({});
144144

145145
if(sort){
146146
_query.order = [];
@@ -294,7 +294,7 @@ var <%= service %>sController = {};
294294
}
295295

296296
_query.where = query;
297-
<%= service %>s.updateMany(data, _query)
297+
<%= service %>s.update(data, _query)
298298
.then(function(resp){
299299
res.ok(resp);
300300
})
@@ -311,7 +311,7 @@ var <%= service %>sController = {};
311311
delete data.secure;
312312
}
313313
_query.where = <%= service %>s.where = {_id:id};
314-
<%= service %>s.updateMany(data,_query)
314+
<%= service %>s.update(data,_query)
315315
.then(function(resp){
316316
if(!resp){
317317
next();

template/controller_sql_test.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ it('should update documents', function(done){
313313
var req = {};
314314
req.query = {name: 'Femi'};
315315
req.body = {name: 'Femi Updated'};
316-
<%= object %>s.updateMany(req, res, next);
316+
<%= object %>s.update(req, res, next);
317317
});
318318
it('should update a document', function(done){
319319
var next = function(err){

template/controller_test.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ it('should update documents', function(done){
305305
var req = {};
306306
req.query = {name: 'Femi'};
307307
req.body = {name: 'Femi Updated'};
308-
<%= object %>s.updateMany(req, res, next);
308+
<%= object %>s.update(req, res, next);
309309
});
310310
it('should update a document', function(done){
311311
var next = function(err){

template/model_sql_test.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('<%= service %> Model',function(){
6464

6565
it('should update data', function(done){
6666
var cb = sinon.spy();
67-
var my<%= object %> = <%= service %>.updateMany({name: 'Olaoluwa'}, { where: {name: 'femi'}});
67+
var my<%= object %> = <%= service %>.update({name: 'Olaoluwa'}, { where: {name: 'femi'}});
6868

6969
my<%= object %>.then(function(res){
7070
cb();
@@ -122,7 +122,7 @@ describe('<%= service %> Model',function(){
122122
var my<%= object %> = <%= service %>.create({name: 'i am a demigod!'});
123123
my<%= object %>.then(function(res){
124124
id2 = res._id;
125-
return <%= service %>.updateMany({name: 'This is the titan'}, {where: {_id: id}});
125+
return <%= service %>.update({name: 'This is the titan'}, {where: {_id: id}});
126126
})
127127
.then(function(res){
128128
return <%= service %>.findOne({where: {name: 'This is the titan'}});
@@ -162,7 +162,7 @@ describe('<%= service %> Model',function(){
162162
});
163163

164164
it('should count returned records', function(done){
165-
var my<%= object %> = <%= service %>.estimatedDocumentCount({where: {name: 'This is the titan'}});
165+
var my<%= object %> = <%= service %>.count({where: {name: 'This is the titan'}});
166166

167167
my<%= object %>.then(function(res){
168168
res.should.be.a.number; /* jslint ignore:line */

0 commit comments

Comments
 (0)