Permalink
Browse files

expose getDrawNumber and getDrawDate to clients

  • Loading branch information...
1 parent eb5cc3e commit 696a230969ff831c1ace846114f3c5a2d47d782a @Devon-Olivier committed Jan 4, 2013
Showing with 37 additions and 0 deletions.
  1. +37 −0 lottoplus/mongo.js
View
37 lottoplus/mongo.js
@@ -93,6 +93,25 @@ exports.createDriver = function createDriver(options){
//TODO getDrawDateRange and getDrawNumberRange have common logic
//ABSTRACT AWAY!!
+ _adapter.getDrawDate = function getDrawDate(aMoment, drawDateCallback){
+ var date = aMoment.toDate();
+ var queryObject = {'date': date};
+ var job = function(jobCallback){
+ _lottoplusDB.collection('draws').findOne(queryObject, function findCallback(error, draw){
+ if(error){
+ jobCallback(new ERROR.DATABASE('mongo query error', error), null);
+ return;
+ }
+ if(draw === null){
+ jobCallback(new ERROR.NODRAW('draw does not exist', date), null);
+ return;
+ }
+ jobCallback(null, draw);
+ });
+ };
+ this.doJob(job, drawDateCallback);
+ };
+
_adapter.getDrawDateRange = function getDrawDateRange(range, drawDateRangeCallback){
//TODO: ensure that range is correct type
var startDate = range.start.toDate();
@@ -130,6 +149,24 @@ exports.createDriver = function createDriver(options){
this.doJob(job, drawDateRangeCallback);
};
+ _adapter.getDrawNumber = function getDrawNumber(number, drawNumberCallback){
+ var queryObject = {'number': number};
+ var job = function(jobCallback){
+ _lottoplusDB.collection('draws').findOne(queryObject, function findCallback(error, draw){
+ if(error){
+ jobCallback(new ERROR.DATABASE('mongo query error', error), null);
+ return;
+ }
+ if(draw === null){
+ jobCallback(new ERROR.NODRAW('draw does not exist', date), null);
+ return;
+ }
+ jobCallback(null, draw);
+ });
+ };
+ this.doJob(job, drawNumberCallback);
+ };
+
_adapter.getDrawNumberRange = function getDrawNumberRange(range, drawNumberRangeCallback){
//TODO: we should make sure the start and end are positive INTEGERS
var rangeStart = +range.start;

0 comments on commit 696a230

Please sign in to comment.