Subscription.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. overleaf: {
  38. id: {
  39. type: Number,
  40. index: {
  41. unique: true,
  42. partialFilterExpression: { 'overleaf.id': { $exists: true } },
  43. },
  44. },
  45. },
  46. recurlyStatus: {
  47. state: {
  48. type: String,
  49. },
  50. trialStartedAt: {
  51. type: Date,
  52. },
  53. trialEndsAt: {
  54. type: Date,
  55. },
  56. },
  57. ssoConfig: { type: ObjectId, ref: 'SSOConfig' },
  58. },
  59. { minimize: false }
  60. )
  61. // Subscriptions have no v1 data to fetch
  62. SubscriptionSchema.method('fetchV1Data', function (callback) {
  63. callback(null, this)
  64. })
  65. exports.Subscription = mongoose.model('Subscription', SubscriptionSchema)
  66. exports.SubscriptionSchema = SubscriptionSchema