Subscription.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. teamName: { type: String },
  27. teamNotice: { type: String },
  28. planCode: { type: String },
  29. groupPlan: { type: Boolean, default: false },
  30. managedUsersEnabled: { type: Boolean, default: false },
  31. membersLimit: { type: Number, default: 0 },
  32. customAccount: Boolean,
  33. features: {
  34. managedUsers: { type: Boolean, default: null },
  35. groupSSO: { type: Boolean, default: null },
  36. },
  37. addOns: Schema.Types.Mixed,
  38. overleaf: {
  39. id: {
  40. type: Number,
  41. index: {
  42. unique: true,
  43. partialFilterExpression: { 'overleaf.id': { $exists: true } },
  44. },
  45. },
  46. },
  47. recurlyStatus: {
  48. state: {
  49. type: String,
  50. },
  51. trialStartedAt: {
  52. type: Date,
  53. },
  54. trialEndsAt: {
  55. type: Date,
  56. },
  57. },
  58. v1_id: {
  59. type: Number,
  60. required: false,
  61. min: 1,
  62. },
  63. salesforce_id: {
  64. type: String,
  65. required: false,
  66. validate: {
  67. validator: function (salesforceId) {
  68. return (
  69. salesforceId == null ||
  70. salesforceId === '' ||
  71. salesforceId.match(/^(?:[A-Za-z0-9]{15}|[A-Za-z0-9]{18})$/)
  72. )
  73. },
  74. },
  75. },
  76. ssoConfig: { type: ObjectId, ref: 'SSOConfig' },
  77. },
  78. { minimize: false }
  79. )
  80. // Subscriptions have no v1 data to fetch
  81. SubscriptionSchema.method('fetchV1Data', function (callback) {
  82. callback(null, this)
  83. })
  84. exports.Subscription = mongoose.model('Subscription', SubscriptionSchema)
  85. exports.SubscriptionSchema = SubscriptionSchema