Subscription.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. recurlyStatus: {
  40. state: {
  41. type: String,
  42. },
  43. trialStartedAt: {
  44. type: Date,
  45. },
  46. trialEndsAt: {
  47. type: Date,
  48. },
  49. },
  50. })
  51. // Subscriptions have no v1 data to fetch
  52. SubscriptionSchema.method('fetchV1Data', function (callback) {
  53. callback(null, this)
  54. })
  55. exports.Subscription = mongoose.model('Subscription', SubscriptionSchema)
  56. exports.SubscriptionSchema = SubscriptionSchema