feat: Create and use dynamic active donation counts

This commit is contained in:
Bouncey
2018-11-29 14:24:17 +00:00
committed by mrugesh mohapatra
parent 331ea3ebf9
commit 8fab33ba99
6 changed files with 111 additions and 58 deletions

View File

@ -2,14 +2,18 @@ import { Observable } from 'rx';
export default function(Donation) {
Donation.on('dataSourceAttached', () => {
Donation.find$ = Observable.fromNodeCallback(Donation.find.bind(Donation));
Donation.findOne$ = Observable.fromNodeCallback(
Donation.findOne.bind(Donation)
);
Donation.prototype.validate$ = Observable.fromNodeCallback(
Donation.prototype.validate
);
Donation.prototype.destroy$ = Observable.fromNodeCallback(
Donation.prototype.destroy
);
});
function getCurrentActiveDonationCount$() {
// eslint-disable-next-line no-undefined
return Donation.find$({ where: { endDate: undefined } }).map(
instances => instances.length
);
}
Donation.getCurrentActiveDonationCount$ = getCurrentActiveDonationCount$;
}