ProjectInvite.mjs 805 B

12345678910111213141516171819202122232425262728293031323334353637
  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. tokenHmac: String,
  14. sendingUserId: ObjectId,
  15. projectId: ObjectId,
  16. privileges: String,
  17. createdAt: { type: Date, default: Date.now },
  18. expires: {
  19. type: Date,
  20. default: ExpiryDate,
  21. index: { expireAfterSeconds: 10 },
  22. },
  23. },
  24. {
  25. collection: 'projectInvites',
  26. minimize: false,
  27. }
  28. )
  29. export const ProjectInvite = mongoose.model(
  30. 'ProjectInvite',
  31. ProjectInviteSchema
  32. )