Comparing version 0.10.1 to 0.11.0
@@ -131,3 +131,4 @@ var Book, Q, entry, mongoose, _; | ||
Book.prototype.ledger = function(query, populate) { | ||
var deferred, pagination, pop, q, _i, _len; | ||
var deferred, pagination, pop, q, _i, _len, | ||
_this = this; | ||
if (populate == null) { | ||
@@ -148,21 +149,50 @@ populate = null; | ||
if (pagination) { | ||
q.skip((pagination.page - 1) * pagination.perPage).limit(pagination.perPage); | ||
} | ||
q.sort({ | ||
datetime: -1, | ||
timestamp: -1 | ||
}); | ||
if (populate) { | ||
for (_i = 0, _len = populate.length; _i < _len; _i++) { | ||
pop = populate[_i]; | ||
q.populate(pop); | ||
this.transactionModel.count(query, function(err, count) { | ||
var pop, _i, _len; | ||
q.skip((pagination.page - 1) * pagination.perPage).limit(pagination.perPage); | ||
q.sort({ | ||
datetime: -1, | ||
timestamp: -1 | ||
}); | ||
if (populate) { | ||
for (_i = 0, _len = populate.length; _i < _len; _i++) { | ||
pop = populate[_i]; | ||
q.populate(pop); | ||
} | ||
} | ||
return q.exec(function(err, results) { | ||
if (err) { | ||
return deferred.reject(err); | ||
} else { | ||
return deferred.resolve({ | ||
results: results, | ||
total: count | ||
}); | ||
} | ||
}); | ||
}); | ||
} else { | ||
q.sort({ | ||
datetime: -1, | ||
timestamp: -1 | ||
}); | ||
if (populate) { | ||
for (_i = 0, _len = populate.length; _i < _len; _i++) { | ||
pop = populate[_i]; | ||
q.populate(pop); | ||
} | ||
} | ||
q.exec(function(err, results) { | ||
var returnVal; | ||
if (err) { | ||
return deferred.reject(err); | ||
} else { | ||
returnVal = { | ||
results: results, | ||
total: results.length | ||
}; | ||
return deferred.resolve(returnVal); | ||
} | ||
}); | ||
} | ||
q.exec(function(err, results) { | ||
if (err) { | ||
return deferred.reject(err); | ||
} else { | ||
return deferred.resolve(results); | ||
} | ||
}); | ||
return deferred.promise; | ||
@@ -169,0 +199,0 @@ }; |
{ | ||
"name": "medici", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "Simple double-entry accounting for Node + Mongoose", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -43,3 +43,2 @@ var medici, moment, mongoose; | ||
}).then(function(bal) { | ||
console.log('Balance:', bal); | ||
bal.should.equal(-1200); | ||
@@ -49,3 +48,2 @@ return book.balance({ | ||
}).then(function(bal) { | ||
console.log('Checked balance of accts receivable, got to here'); | ||
bal.should.equal(-1200); | ||
@@ -59,4 +57,2 @@ return book.balance({ | ||
}); | ||
}, function(err) { | ||
return console.log(err.stack); | ||
}); | ||
@@ -69,4 +65,4 @@ }); | ||
account: 'Assets' | ||
}).then(function(results) { | ||
results.length.should.equal(2); | ||
}).then(function(res) { | ||
res.results.length.should.equal(2); | ||
return done(); | ||
@@ -103,7 +99,8 @@ }); | ||
account: ['Assets', 'Income'] | ||
}).then(function(results) { | ||
var res, _i, _len; | ||
results.length.should.equal(6); | ||
for (_i = 0, _len = results.length; _i < _len; _i++) { | ||
res = results[_i]; | ||
}).then(function(response) { | ||
var res, _i, _len, _ref; | ||
response.results.length.should.equal(6); | ||
_ref = response.results; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
res = _ref[_i]; | ||
((res.account_path.indexOf('Assets') >= 0) || (res.account_path.indexOf('Income') >= 0)).should.equal(true); | ||
@@ -121,7 +118,7 @@ } | ||
page: 3 | ||
}).then(function(results) { | ||
console.log('Got to here', results); | ||
results.length.should.equal(2); | ||
results[0].memo.should.equal('Test Entry 2'); | ||
results[1].memo.should.equal('Test Entry 2'); | ||
}).then(function(response) { | ||
response.results.length.should.equal(2); | ||
response.total.should.equal(6); | ||
response.results[0].memo.should.equal('Test Entry 2'); | ||
response.results[1].memo.should.equal('Test Entry 2'); | ||
return done(); | ||
@@ -128,0 +125,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43965
715