Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / server / serializers / rest / troupes / pro-org-strategy.js
blob9987cb24f47a58f34fd1d5cbdb705e717d961043
1 'use strict';
3 var billingService = require('../../../services/billing-service');
5 function getOwner(uri) {
6 return uri.split('/', 1).shift();
9 function ProOrgStrategy() {
10 this.proOrgs = null;
13 ProOrgStrategy.prototype = {
14 preload: function(troupes) {
15 var uris = troupes
16 .map(function(troupe) {
17 if (!troupe.uri) return; // one-to-one
18 return getOwner(troupe.uri);
20 .filter(function(room) {
21 return !!room; // this removes the `undefined` left behind (one-to-ones)
23 .uniq();
25 return billingService
26 .findActiveOrgPlans(uris.toArray())
27 .bind(this)
28 .then(function(subscriptions) {
29 var proOrgs = {};
30 subscriptions.forEach(function(subscription) {
31 var uri = subscription.uri || '';
32 proOrgs[uri.toLowerCase()] = !!subscription;
33 });
35 this.proOrgs = proOrgs;
36 });
39 map: function(troupe) {
40 if (!troupe || !troupe.uri) return undefined;
42 var owner = getOwner(troupe.uri).toLowerCase();
43 return this.proOrgs[owner];
46 name: 'ProOrgStrategy'
49 module.exports = ProOrgStrategy;