Skip to content

Commit

Permalink
Merge pull request #8 from Catlite91/add-return-statement
Browse files Browse the repository at this point in the history
add return statements
  • Loading branch information
i5ting committed Jun 7, 2016
2 parents 4579e07 + 04596f6 commit 0ac806e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ function MongooseDao (Model){

// create
MongooseDao.prototype.create = function(doc, cb) {
this.model.create(doc, cb);
return this.model.create(doc, cb);
};

// read
MongooseDao.prototype.getById = function(id, cb) {
this.model.findOne({_id:id}, cb);
return this.model.findOne({_id:id}, cb);
};

MongooseDao.prototype.count = function() {
Expand All @@ -41,30 +41,30 @@ MongooseDao.prototype.count = function() {
//default : count(cb)
cb = arguments[0];
}
this.model.count(query, cb);
return this.model.count(query, cb);
};

MongooseDao.prototype.query = MongooseDao.prototype.find = MongooseDao.prototype.getByQuery = function(query, cb) {
this.model.find(query, cb);
return this.model.find(query, cb);
};

MongooseDao.prototype.all = MongooseDao.prototype.getAll = function(cb) {
this.model.find({}, cb);
return this.model.find({}, cb);
};

MongooseDao.prototype.one = MongooseDao.prototype.findOne = function(query, cb) {
this.model.findOne(query, cb);
return this.model.findOne(query, cb);
};

// update
MongooseDao.prototype.updateById = function(id, update, cb) {
// console.log('MongooseDao.prototype.updateById' + update);
this.updateOne({_id:id}, update, cb);
return this.updateOne({_id:id}, update, cb);
};

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

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

this.model.update(conditions, update, opt, cb);
return this.model.update(conditions, update, opt, cb);
};

// delete
MongooseDao.prototype.delete = MongooseDao.prototype.remove = function(query, cb){
this.model.remove(query, cb);
return this.model.remove(query, cb);
};

MongooseDao.prototype.deleteAll = MongooseDao.prototype.removeAll = function(cb){
this.delete({}, cb);
return this.delete({}, cb);
};

MongooseDao.prototype.deleteById = MongooseDao.prototype.removeById = function(id, cb) {
// console.log('MongooseDao.prototype.deleteById');
this.delete({_id: id}, cb);
return this.delete({_id: id}, cb);
};

// pagination
Expand Down Expand Up @@ -136,7 +136,7 @@ MongooseDao.prototype.latest = MongooseDao.prototype.top = MongooseDao.prototype
cb = arguments[0];
}

this.model.find(q).sort(sort).limit(n).exec(cb);
return this.model.find(q).sort(sort).limit(n).exec(cb);
};

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

this.model.find(q).sort(sort).limit(n).exec(cb);
return this.model.find(q).sort(sort).limit(n).exec(cb);
};

// private
Expand Down

0 comments on commit 0ac806e

Please sign in to comment.