Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / api / v1 / user / suggested-rooms.js
blob0debce91c9d4d01b2c4273b00f17987dbb61a7d5
1 'use strict';
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;
12 module.exports = {
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);
24     });
25   }