-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b695229
commit 141c462
Showing
6 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const queries = require('./house.queries.js'); | ||
const Promise = require('bluebird'); | ||
|
||
module.exports = function checkUsersPresence(){ | ||
sails.log.debug(`House : checkUsersPresence`); | ||
|
||
// first, get the time a user is considered not at home anymore | ||
return gladys.param.getValue('USER_TIME_BEFORE_CONSIDERING_LEFT_HOME') | ||
.then((timeBeforeLeftInMinute) => { | ||
|
||
// get all houses | ||
return [timeBeforeLeftInMinute, gladys.house.getAll()]; | ||
}) | ||
.spread((timeBeforeLeftInMinute, houses) => { | ||
|
||
return [houses, | ||
Promise.map(houses, function(house) { | ||
return gladys.utils.sql(queries.getUserAtHomeAndNotSeenSince, [house.id, house.id, timeBeforeLeftInMinute]); | ||
}) | ||
]; | ||
}) | ||
.spread((houses, usersArray) => { | ||
|
||
// foreach house | ||
return Promise.map(houses, function(house, index) { | ||
|
||
// foreach user in this house and not put as | ||
return Promise.map(usersArray[index], function(user) { | ||
sails.log.debug(`House : checkUserPresence : Putting user ${user.id} as left house : ${house.id}`); | ||
return gladys.event.create({code: 'left-home', user: user.id, house: house.id}); | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var should = require('should'); | ||
var validateHouse = require('../../validator/houseValidator.js'); | ||
|
||
describe('House', function() { | ||
|
||
describe('checkUserPresence', function() { | ||
|
||
it('should check if user is present and not seen since a given time', function (done) { | ||
|
||
gladys.house.checkUsersPresence() | ||
.then(function(result){ | ||
|
||
done(); | ||
}).catch(done); | ||
}); | ||
|
||
}); | ||
}); |