41 lines
747 B
JavaScript
41 lines
747 B
JavaScript
import mongoose from "mongoose";
|
|
|
|
const InvitationSchema = new mongoose.Schema({
|
|
code: {
|
|
type: String,
|
|
required: true,
|
|
unique: true,
|
|
},
|
|
createdBy: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'Staffs',
|
|
required: true,
|
|
},
|
|
isUsed: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
usedBy: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'Vendor',
|
|
default: null,
|
|
},
|
|
expiresAt: {
|
|
type: Date,
|
|
required: true,
|
|
},
|
|
createdAt: {
|
|
type: Date,
|
|
default: Date.now,
|
|
},
|
|
usedAt: {
|
|
type: Date,
|
|
default: null,
|
|
}
|
|
});
|
|
|
|
InvitationSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
InvitationSchema.index({ code: 1 });
|
|
|
|
export default mongoose.model("Invitation", InvitationSchema);
|