Skip to content

Commit 0ac806e

Browse files
committed
Merge pull request #8 from Catlite91/add-return-statement
add return statements
2 parents 4579e07 + 04596f6 commit 0ac806e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lib/dao.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ function MongooseDao (Model){
2222

2323
// create
2424
MongooseDao.prototype.create = function(doc, cb) {
25-
this.model.create(doc, cb);
25+
return this.model.create(doc, cb);
2626
};
2727

2828
// read
2929
MongooseDao.prototype.getById = function(id, cb) {
30-
this.model.findOne({_id:id}, cb);
30+
return this.model.findOne({_id:id}, cb);
3131
};
3232

3333
MongooseDao.prototype.count = function() {
@@ -41,30 +41,30 @@ MongooseDao.prototype.count = function() {
4141
//default : count(cb)
4242
cb = arguments[0];
4343
}
44-
this.model.count(query, cb);
44+
return this.model.count(query, cb);
4545
};
4646

4747
MongooseDao.prototype.query = MongooseDao.prototype.find = MongooseDao.prototype.getByQuery = function(query, cb) {
48-
this.model.find(query, cb);
48+
return this.model.find(query, cb);
4949
};
5050

5151
MongooseDao.prototype.all = MongooseDao.prototype.getAll = function(cb) {
52-
this.model.find({}, cb);
52+
return this.model.find({}, cb);
5353
};
5454

5555
MongooseDao.prototype.one = MongooseDao.prototype.findOne = function(query, cb) {
56-
this.model.findOne(query, cb);
56+
return this.model.findOne(query, cb);
5757
};
5858

5959
// update
6060
MongooseDao.prototype.updateById = function(id, update, cb) {
6161
// console.log('MongooseDao.prototype.updateById' + update);
62-
this.updateOne({_id:id}, update, cb);
62+
return this.updateOne({_id:id}, update, cb);
6363
};
6464

6565
MongooseDao.prototype.updateOne = function(conditions, update, cb) {
6666
// console.log('MongooseDao.prototype.updateById' + update);
67-
this.update(conditions, update , {multi: false}, cb);
67+
return this.update(conditions, update , {multi: false}, cb);
6868
};
6969

7070
// way1: conditions, update , cb
@@ -91,21 +91,21 @@ MongooseDao.prototype.update = function() {
9191
var opt = { multi: true };
9292
_extend(opt, _options);
9393

94-
this.model.update(conditions, update, opt, cb);
94+
return this.model.update(conditions, update, opt, cb);
9595
};
9696

9797
// delete
9898
MongooseDao.prototype.delete = MongooseDao.prototype.remove = function(query, cb){
99-
this.model.remove(query, cb);
99+
return this.model.remove(query, cb);
100100
};
101101

102102
MongooseDao.prototype.deleteAll = MongooseDao.prototype.removeAll = function(cb){
103-
this.delete({}, cb);
103+
return this.delete({}, cb);
104104
};
105105

106106
MongooseDao.prototype.deleteById = MongooseDao.prototype.removeById = function(id, cb) {
107107
// console.log('MongooseDao.prototype.deleteById');
108-
this.delete({_id: id}, cb);
108+
return this.delete({_id: id}, cb);
109109
};
110110

111111
// pagination
@@ -136,7 +136,7 @@ MongooseDao.prototype.latest = MongooseDao.prototype.top = MongooseDao.prototype
136136
cb = arguments[0];
137137
}
138138

139-
this.model.find(q).sort(sort).limit(n).exec(cb);
139+
return this.model.find(q).sort(sort).limit(n).exec(cb);
140140
};
141141

142142
// TODO: impl page by lastId
@@ -184,7 +184,7 @@ MongooseDao.prototype.pageByLastId = function(){
184184
cb = arguments[1];
185185
}
186186

187-
this.model.find(q).sort(sort).limit(n).exec(cb);
187+
return this.model.find(q).sort(sort).limit(n).exec(cb);
188188
};
189189

190190
// private

0 commit comments

Comments
 (0)