Handle the input data in record method

This commit is contained in:
Ionică Bizău 2015-09-13 17:44:40 +03:00
parent 0622a48333
commit d04935e340
1 changed files with 17 additions and 4 deletions

View File

@ -109,8 +109,7 @@ GitStats.prototype.record = function (data, callback) {
delete data.url;
}
// Get stats
self.get(function (err, stats) {
function modify (err, stats) {
var commits = stats.commits
, day = data.date.format(DATE_FORMAT)
@ -119,8 +118,22 @@ GitStats.prototype.record = function (data, callback) {
today[data.hash] = 1;
self.save(stats, callback);
});
if (data.save === false) {
callback(null, stats);
} else {
self.save(stats, callback);
}
return stats;
}
// Check if we have input data
if (data._data) {
return modify(null, data._data);
} else {
// Get stats
self.get(modify);
}
return self;
};