team.js 1.26 KB
Newer Older
mntmn's avatar
mntmn committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

module.exports.teamSchema = mongoose.Schema({
  name: String,
  subdomain: String,
  creator: {
    type: Schema.Types.ObjectId,
    ref: 'User'
  },
  admins: [{
    type: Schema.Types.ObjectId,
    ref: 'User'
  }],
  invitation_codes: [String],
  avatar_thumb_uri: String,
  avatar_uri: String,
  payment_type: {
    type: String,
    default: "auto"
  },
  payment_plan_key: String,
  payment_subscription_id: String,
  blocked_at: {
    type: Date
  },
  upgraded_at: {
    type: Date
  },
  created_at: {
    type: Date,
    default: Date.now
  },
  updated_at: {
    type: Date,
    default: Date.now
  }
});

module.exports.teamSchema.index({
  creator: 1
});

module.exports.teamSchema.statics.getTeamForHost = (host, cb) => {

48
  if (host != "127.0.0.1:9666") { //phantomjs check
mntmn's avatar
mntmn committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    let subDomainParts = host.split('.');

    if (subDomainParts.length > 2) {
      const subdomain = subDomainParts[0];

      if (subdomain != "www") {
        Team.findOne({
          subdomain: subdomain
        }).exec((err, team) => {
          cb(err, team, subdomain)
        });
      } else {
        cb(null, null)
      }

    } else {
      cb(null, null);
    }
  } else {
    cb(null, null);
  }
}