2026-01-16 20:29:54 +00:00
|
|
|
import { Schema, model, type Types } from "mongoose";
|
2026-06-09 12:34:15 -07:00
|
|
|
import type { Invite } from "@/domain/invites/invite.type.js";
|
2026-01-16 20:29:54 +00:00
|
|
|
|
|
|
|
|
type InviteDocumentBase = Omit<Invite, "id" | "teamId" | "createdAt" | "updatedAt" | "expiry"> & {
|
|
|
|
|
teamId: Types.ObjectId;
|
|
|
|
|
expiry: Date;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface InviteDocument extends InviteDocumentBase {
|
|
|
|
|
_id: Types.ObjectId;
|
|
|
|
|
createdAt: Date;
|
|
|
|
|
updatedAt: Date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const InviteSchema = new Schema<InviteDocument>(
|
|
|
|
|
{
|
|
|
|
|
email: { type: String, required: true, unique: true },
|
|
|
|
|
teamId: { type: Schema.Types.ObjectId, ref: "Team", immutable: true, required: true },
|
|
|
|
|
role: { type: [String], required: true, default: ["user"] },
|
|
|
|
|
token: { type: String, required: true },
|
|
|
|
|
expiry: { type: Date, default: Date.now, expires: 3600 },
|
|
|
|
|
},
|
|
|
|
|
{ timestamps: true }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const InviteModel = model<InviteDocument>("Invite", InviteSchema);
|
|
|
|
|
|
|
|
|
|
export type { InviteDocument };
|
|
|
|
|
export { InviteModel };
|
|
|
|
|
export default InviteModel;
|