Subscription.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const mongoose = require('../infrastructure/Mongoose')
  2. const { TeamInviteSchema } = require('./TeamInvite')
  3. const { Schema } = mongoose
  4. const { ObjectId } = Schema
  5. const SubscriptionSchema = new Schema({
  6. admin_id: {
  7. type: ObjectId,
  8. ref: 'User',
  9. index: { unique: true, dropDups: true },
  10. },
  11. manager_ids: {
  12. type: [ObjectId],
  13. ref: 'User',
  14. required: true,
  15. validate: function (managers) {
  16. // require at least one manager
  17. return !!managers.length
  18. },
  19. },
  20. member_ids: [{ type: ObjectId, ref: 'User' }],
  21. invited_emails: [String],
  22. teamInvites: [TeamInviteSchema],
  23. recurlySubscription_id: String,
  24. teamName: { type: String },
  25. teamNotice: { type: String },
  26. planCode: { type: String },
  27. groupPlan: { type: Boolean, default: false },
  28. membersLimit: { type: Number, default: 0 },
  29. customAccount: Boolean,
  30. overleaf: {
  31. id: {
  32. type: Number,
  33. index: {
  34. unique: true,
  35. partialFilterExpression: { 'overleaf.id': { $exists: true } },
  36. },
  37. },
  38. },
  39. })
  40. // Subscriptions have no v1 data to fetch
  41. SubscriptionSchema.method('fetchV1Data', function (callback) {
  42. callback(null, this)
  43. })
  44. exports.Subscription = mongoose.model('Subscription', SubscriptionSchema)
  45. exports.SubscriptionSchema = SubscriptionSchema