Skip to content

Commit

Permalink
fixed issue with looking up dates
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Jan 6, 2015
1 parent 509fdc4 commit a878813
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/routes/config/schedule/get_day.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ module.exports = {
tags:['workouts', 'schedule'],
validate: {
params: {
date: Joi.date().required()
date: Joi.string().required()
}
},
cors: {
origin: ['http://localhost:8100'],
credentials: true
},
handler: function(request, reply){
var params = {date: request.params.date, userId:request.auth.credentials.id};
console.log(request.params.date);
var date = convertStringToDate(request.params.date),
params = {date: date, userId:request.auth.credentials.id};
Schedule.findOne(params, function(err, day){
if(err || !day){console.log('ERROR: Schedule.findOne', err);}
reply({day:day}).code(err ? 418 : 200);
});
}
};

// HELPER FUNCTIONS //
function convertStringToDate(s){
var parts = s.split('-');
return new Date(parseInt(parts[0],10),parseInt(parts[1],10) - 1,parseInt(parts[2],10));
}

0 comments on commit a878813

Please sign in to comment.