Skip to content

Commit

Permalink
POST /user/:id/house/:id/seen : Mark user as seen in a specific house
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed Sep 16, 2017
1 parent bef812f commit 6bd5f21
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
15 changes: 15 additions & 0 deletions api/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ module.exports = {
id: req.session.User.id
};
res.json(user);
},

/**
* @api {post} /user/:id/house/:id/seen Mark user as seen
* @apiName Mark user as seen
* @apiGroup User
* @apiPermission authenticated
*
* @apiDescription Mark user as seen in a house
*
*/
seen: function(req, res, next){
gladys.house.userSeen({user: req.params.user_id, house: req.params.house_id})
.then((result) => res.json(result))
.catch(next);
}

};
3 changes: 2 additions & 1 deletion config/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ module.exports.policies = {
login: [],
delete: ['checkToken', 'isAdmin'],
update: ['checkToken'],
whoami: ['checkToken']
whoami: ['checkToken'],
seen: ['checkToken']
},
Welcome : {
index: [],
Expand Down
1 change: 1 addition & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ module.exports.routes = {
'patch /user/:id': 'UserController.update',
'delete /user/:id': 'UserController.delete',
'get /user/whoami': 'UserController.whoami',
'post /user/:user_id/house/:house_id/seen': 'UserController.seen',


// Weather
Expand Down
26 changes: 26 additions & 0 deletions test/unit/api/controllers/User/User.seen.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var request = require('supertest');
var validateUser = require('../../validator/userValidator.js');

describe('UserController', function() {

describe('seen', function() {

it('should mark user as seen', function (done) {

request(sails.hooks.http.app)
.post('/user/1/house/1/seen?token=test')
.expect(200)
.end(function(err, res) {
if(err) return done(err);

res.body.should.have.property('user', 1);
res.body.should.have.property('house', 1);
done();
});

});

});


});

0 comments on commit 6bd5f21

Please sign in to comment.