ProjectInvite.mjs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import mongoose from '../infrastructure/Mongoose.mjs'
  2. const { Schema } = mongoose
  3. const { ObjectId } = Schema
  4. export const EXPIRY_IN_SECONDS = 60 * 60 * 24 * 30
  5. const ExpiryDate = function () {
  6. const timestamp = new Date()
  7. timestamp.setSeconds(timestamp.getSeconds() + EXPIRY_IN_SECONDS)
  8. return timestamp
  9. }
  10. export const ProjectInviteSchema = new Schema(
  11. {
  12. email: String,
  13. encryptedToken: String,
  14. tokenHmac: String,
  15. sendingUserId: ObjectId,
  16. projectId: ObjectId,
  17. // privileges contains a PrivilegeLevels value, which may be Boolean `false` or a String
  18. privileges: {
  19. type: Schema.Types.Union,
  20. of: [String, Boolean],
  21. },
  22. createdAt: { type: Date, default: Date.now },
  23. expires: {
  24. type: Date,
  25. default: ExpiryDate,
  26. index: { expireAfterSeconds: 10 },
  27. },
  28. reusable: { type: Boolean, default: false },
  29. subscriptionId: ObjectId,
  30. },
  31. {
  32. collection: 'projectInvites',
  33. minimize: false,
  34. }
  35. )
  36. export const ProjectInvite = mongoose.model(
  37. 'ProjectInvite',
  38. ProjectInviteSchema
  39. )