mirror of
https://github.com/spacedeck/spacedeck-open.git
synced 2025-12-16 01:47:30 +01:00
initial commit.
This commit is contained in:
70
models/team.js
Normal file
70
models/team.js
Normal file
@@ -0,0 +1,70 @@
|
||||
'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) => {
|
||||
|
||||
if (host != "127.0.0.1:9000") { //phantomjs check
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user