Subscription.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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: { type: [ObjectId], ref: 'User', required: true },
  12. member_ids: [{ type: ObjectId, ref: 'User' }],
  13. invited_emails: [String],
  14. teamInvites: [TeamInviteSchema],
  15. recurlySubscription_id: String,
  16. teamName: { type: String },
  17. teamNotice: { type: String },
  18. planCode: { type: String },
  19. groupPlan: { type: Boolean, default: false },
  20. membersLimit: { type: Number, default: 0 },
  21. customAccount: Boolean,
  22. overleaf: {
  23. id: {
  24. type: Number,
  25. index: {
  26. unique: true,
  27. partialFilterExpression: { 'overleaf.id': { $exists: true } }
  28. }
  29. }
  30. }
  31. })
  32. SubscriptionSchema.statics.findAndModify = function(query, update, callback) {
  33. const self = this
  34. return this.update(query, update, () => self.findOne(query, callback))
  35. }
  36. // Subscriptions have no v1 data to fetch
  37. SubscriptionSchema.method('fetchV1Data', function(callback) {
  38. callback(null, this)
  39. })
  40. exports.Subscription = mongoose.model('Subscription', SubscriptionSchema)
  41. exports.SubscriptionSchema = SubscriptionSchema