Subscription.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. {
  7. admin_id: {
  8. type: ObjectId,
  9. ref: 'User',
  10. index: { unique: true, dropDups: true },
  11. },
  12. manager_ids: {
  13. type: [ObjectId],
  14. ref: 'User',
  15. required: true,
  16. validate: function (managers) {
  17. // require at least one manager
  18. return !!managers.length
  19. },
  20. },
  21. member_ids: [{ type: ObjectId, ref: 'User' }],
  22. groupPolicy: { type: ObjectId, ref: 'GroupPolicy' },
  23. invited_emails: [String],
  24. teamInvites: [TeamInviteSchema],
  25. recurlySubscription_id: String,
  26. lastSuccesfulSubscription: {
  27. planCode: {
  28. type: String,
  29. },
  30. addOns: Schema.Types.Mixed,
  31. },
  32. timesRevertedDueToFailedPayment: { type: Number, default: 0 },
  33. teamName: { type: String },
  34. teamNotice: { type: String },
  35. planCode: { type: String },
  36. groupPlan: { type: Boolean, default: false },
  37. managedUsersEnabled: { type: Boolean, default: false },
  38. membersLimit: { type: Number, default: 0 },
  39. customAccount: Boolean,
  40. features: {
  41. managedUsers: { type: Boolean, default: true },
  42. groupSSO: { type: Boolean, default: true },
  43. },
  44. addOns: Schema.Types.Mixed,
  45. overleaf: {
  46. id: {
  47. type: Number,
  48. index: {
  49. unique: true,
  50. partialFilterExpression: { 'overleaf.id': { $exists: true } },
  51. },
  52. },
  53. },
  54. recurlyStatus: {
  55. state: {
  56. type: String,
  57. },
  58. trialStartedAt: {
  59. type: Date,
  60. },
  61. trialEndsAt: {
  62. type: Date,
  63. },
  64. },
  65. paymentProvider: {
  66. service: {
  67. type: String,
  68. },
  69. subscriptionId: {
  70. type: String,
  71. },
  72. state: {
  73. type: String,
  74. },
  75. trialStartedAt: {
  76. type: Date,
  77. },
  78. trialEndsAt: {
  79. type: Date,
  80. },
  81. },
  82. collectionMethod: {
  83. type: String,
  84. enum: ['automatic', 'manual'],
  85. default: 'automatic',
  86. },
  87. v1_id: {
  88. type: Number,
  89. required: false,
  90. min: 1,
  91. },
  92. salesforce_id: {
  93. type: String,
  94. required: false,
  95. validate: {
  96. validator: function (salesforceId) {
  97. return (
  98. salesforceId == null ||
  99. salesforceId === '' ||
  100. salesforceId.match(/^(?:[A-Za-z0-9]{15}|[A-Za-z0-9]{18})$/)
  101. )
  102. },
  103. },
  104. },
  105. ssoConfig: { type: ObjectId, ref: 'SSOConfig' },
  106. },
  107. { minimize: false }
  108. )
  109. // Subscriptions have no v1 data to fetch
  110. SubscriptionSchema.method('fetchV1Data', function (callback) {
  111. callback(null, this)
  112. })
  113. exports.Subscription = mongoose.model('Subscription', SubscriptionSchema)
  114. exports.SubscriptionSchema = SubscriptionSchema