Subscription.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: true },
  35. groupSSO: { type: Boolean, default: true },
  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. collectionMethod: {
  59. type: String,
  60. enum: ['automatic', 'manual'],
  61. default: 'automatic',
  62. },
  63. v1_id: {
  64. type: Number,
  65. required: false,
  66. min: 1,
  67. },
  68. salesforce_id: {
  69. type: String,
  70. required: false,
  71. validate: {
  72. validator: function (salesforceId) {
  73. return (
  74. salesforceId == null ||
  75. salesforceId === '' ||
  76. salesforceId.match(/^(?:[A-Za-z0-9]{15}|[A-Za-z0-9]{18})$/)
  77. )
  78. },
  79. },
  80. },
  81. ssoConfig: { type: ObjectId, ref: 'SSOConfig' },
  82. },
  83. { minimize: false }
  84. )
  85. // Subscriptions have no v1 data to fetch
  86. SubscriptionSchema.method('fetchV1Data', function (callback) {
  87. callback(null, this)
  88. })
  89. exports.Subscription = mongoose.model('Subscription', SubscriptionSchema)
  90. exports.SubscriptionSchema = SubscriptionSchema