ProjectInvite.js 877 B

123456789101112131415161718192021222324252627282930313233343536
  1. const mongoose = require('../infrastructure/Mongoose')
  2. const { Schema } = mongoose
  3. const { ObjectId } = Schema
  4. 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. 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. exports.ProjectInvite = mongoose.model('ProjectInvite', ProjectInviteSchema)
  30. exports.ProjectInviteSchema = ProjectInviteSchema
  31. exports.EXPIRY_IN_SECONDS = EXPIRY_IN_SECONDS