3 var env = require('gitter-web-env');
4 var config = env.config;
5 var restSerializer = require('../../../serializers/rest-serializer');
6 var suggestionsService = require('../../../services/suggestions-service');
7 var StatusError = require('statuserror');
9 var EXPIRES_SECONDS = config.get('suggestions:cache-timeout');
10 var EXPIRES_MILLISECONDS = EXPIRES_SECONDS * 1000;
13 id: 'resourceUserSuggestedRoom',
15 index: function(req, res) {
16 if (!req.user) throw new StatusError(401);
18 return suggestionsService.findSuggestionsForUserId(req.user.id).then(function(suggestedRooms) {
19 res.set('Cache-Control', 'public, max-age=' + EXPIRES_SECONDS);
20 res.set('Expires', new Date(Date.now() + EXPIRES_MILLISECONDS).toUTCString());
22 var strategy = restSerializer.TroupeStrategy.createSuggestionStrategy();
23 return restSerializer.serialize(suggestedRooms, strategy);