3 var Promise
= require('bluebird');
4 var TroupeUriStrategy
= require('./troupe-uri-strategy');
5 var billingService
= require('../../services/billing-service');
7 function OrgPlanStrategy() {
10 this.preload = function(orgUris
) {
11 if (orgUris
.isEmpty()) return;
13 return billingService
.findActiveOrgPlans(orgUris
.toArray()).then(function(subscriptions
) {
14 orgsWithPlans
= subscriptions
.reduce(function(memo
, s
) {
15 memo
[s
.uri
.toLowerCase()] = s
.plan
;
23 this.map = function(orgUri
) {
24 return orgsWithPlans
[orgUri
.toLowerCase()];
28 OrgPlanStrategy
.prototype = {
29 name
: 'OrgPlanStrategy'
32 function GitHubOrgStrategy(options
) {
33 var troupeUriStrategy
= new TroupeUriStrategy(options
);
34 var planStrategy
= new OrgPlanStrategy();
36 this.preload = function(orgs
) {
37 var orgUris
= orgs
.map(function(org
) {
41 return Promise
.join(troupeUriStrategy
.preload(orgUris
), planStrategy
.preload(orgUris
));
44 this.map = function(item
) {
45 var plan
= planStrategy
.map(item
.login
);
50 avatar_url
: item
.avatar_url
,
52 absoluteUri
: item
.absoluteUri
,
53 room
: troupeUriStrategy
.map(item
.login
),
59 GitHubOrgStrategy
.prototype = {
60 name
: 'GithubOrgStrategy'
63 module
.exports
= GitHubOrgStrategy
;