Skip to content

Commit

Permalink
calendar.getFirstEventTodayUser()
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed May 28, 2017
1 parent 886bf48 commit d5bf175
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/core/calendar/calendar.getFirstEventTodayUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const queries = require('./calendar.queries.js');

module.exports = function getFirstEventTodayUser(userId) {
return gladys.utils.sqlUnique(queries.getFirstEventTodayUser, [userId]);
};
11 changes: 11 additions & 0 deletions api/core/calendar/calendar.queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ module.exports = {
ORDER BY start
LIMIT 1;
`,

getFirstEventTodayUser: `
SELECT calendarevent.*
FROM calendarevent
INNER JOIN calendar ON (calendarevent.calendar = calendar.id)
WHERE user = ?
AND calendar.active = 1
AND DATE(start) = DATE(NOW())
ORDER BY start
LIMIT 1;
`,

getEventsDates: `
SELECT calendarevent.*
Expand Down
1 change: 1 addition & 0 deletions api/core/calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports.get = require('./calendar.get.js');
module.exports.getEventsDates = require('./calendar.getEventsDates.js');
module.exports.getByService = require('./calendar.getByService.js');
module.exports.getEvents = require('./calendar.getEvents.js');
module.exports.getFirstEventTodayUser = require('./calendar.getFirstEventTodayUser.js');
module.exports.getNextEventUser = require('./calendar.getNextEventUser.js');
module.exports.sync = require('./calendar.sync.js');
module.exports.update = require('./calendar.update.js');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var should = require('should');
var validateCalendarEvent = require('../../validator/calendarEventValidator.js');

describe('Calendar', function() {

describe('getFirstEventTodayUser', function() {

it('should return first event today user', function (done) {

gladys.calendar.getFirstEventTodayUser(1)
.then(function(events){
done();
}).catch(function(err){
if(err.message == 'NotFound') done();
else done(err);
});

});

});

});

0 comments on commit d5bf175

Please sign in to comment.