2019-11-18 09:03:20 -05:00
|
|
|
const mongoose = require('../infrastructure/Mongoose')
|
2019-05-29 05:21:06 -04:00
|
|
|
const { TeamInviteSchema } = require('./TeamInvite')
|
|
|
|
|
|
|
|
const { Schema } = mongoose
|
|
|
|
const { ObjectId } = Schema
|
|
|
|
|
2023-02-28 08:26:18 -05:00
|
|
|
const SubscriptionSchema = new Schema(
|
|
|
|
{
|
|
|
|
admin_id: {
|
|
|
|
type: ObjectId,
|
|
|
|
ref: 'User',
|
|
|
|
index: { unique: true, dropDups: true },
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2023-02-28 08:26:18 -05:00
|
|
|
manager_ids: {
|
|
|
|
type: [ObjectId],
|
|
|
|
ref: 'User',
|
|
|
|
required: true,
|
|
|
|
validate: function (managers) {
|
|
|
|
// require at least one manager
|
|
|
|
return !!managers.length
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
|
|
|
},
|
2023-02-28 08:26:18 -05:00
|
|
|
member_ids: [{ type: ObjectId, ref: 'User' }],
|
2023-06-20 03:38:59 -04:00
|
|
|
groupPolicy: { type: ObjectId, ref: 'GroupPolicy' },
|
2023-02-28 08:26:18 -05:00
|
|
|
invited_emails: [String],
|
|
|
|
teamInvites: [TeamInviteSchema],
|
|
|
|
recurlySubscription_id: String,
|
|
|
|
teamName: { type: String },
|
|
|
|
teamNotice: { type: String },
|
|
|
|
planCode: { type: String },
|
|
|
|
groupPlan: { type: Boolean, default: false },
|
|
|
|
membersLimit: { type: Number, default: 0 },
|
|
|
|
customAccount: Boolean,
|
|
|
|
overleaf: {
|
|
|
|
id: {
|
|
|
|
type: Number,
|
|
|
|
index: {
|
|
|
|
unique: true,
|
|
|
|
partialFilterExpression: { 'overleaf.id': { $exists: true } },
|
|
|
|
},
|
|
|
|
},
|
2022-06-16 10:29:49 -04:00
|
|
|
},
|
2023-02-28 08:26:18 -05:00
|
|
|
recurlyStatus: {
|
|
|
|
state: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
trialStartedAt: {
|
|
|
|
type: Date,
|
|
|
|
},
|
|
|
|
trialEndsAt: {
|
|
|
|
type: Date,
|
|
|
|
},
|
2022-06-16 10:29:49 -04:00
|
|
|
},
|
|
|
|
},
|
2023-02-28 08:26:18 -05:00
|
|
|
{ minimize: false }
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
// Subscriptions have no v1 data to fetch
|
2021-04-14 09:17:21 -04:00
|
|
|
SubscriptionSchema.method('fetchV1Data', function (callback) {
|
2019-11-18 09:03:20 -05:00
|
|
|
callback(null, this)
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-11-18 09:03:20 -05:00
|
|
|
exports.Subscription = mongoose.model('Subscription', SubscriptionSchema)
|
2019-05-29 05:21:06 -04:00
|
|
|
exports.SubscriptionSchema = SubscriptionSchema
|