3 var persistence
= require('gitter-web-persistence');
4 var mongoUtils
= require('gitter-web-persistence-utils/lib/mongo-utils');
5 var Promise
= require('bluebird');
6 const mongoReadPrefs
= require('gitter-web-persistence-utils/lib/mongo-read-prefs');
8 function toLowerCase(value
) {
9 return value
&& value
.toLowerCase();
13 * For exporting things
15 function getCursorByUserId(userId
) {
16 const cursor
= persistence
.Subscription
.find({
20 .read(mongoReadPrefs
.secondaryPreferred
)
27 function findActiveOrgPlans(orgUris
) {
28 if (!orgUris
|| !orgUris
.length
) return Promise
.resolve([]);
30 var query
= mongoUtils
.fieldInPredicate('lcUri', orgUris
.map(toLowerCase
), {
31 subscriptionType
: 'ORG',
35 return persistence
.Subscription
.find(query
).exec();
38 function findActivePlan(uri
) {
39 var lcUri
= toLowerCase(uri
);
41 return persistence
.Subscription
.findOne({
47 function findActivePlans(uris
) {
48 if (!uris
|| !uris
.length
) return Promise
.resolve([]);
50 var query
= mongoUtils
.fieldInPredicate('lcUri', uris
.map(toLowerCase
), {
54 return persistence
.Subscription
.find(query
).exec();