Files
Checkmate/server/src/db/models/RecoveryToken.ts
T
2026-01-16 22:03:35 +00:00

28 lines
853 B
TypeScript

import { Schema, model, type Types } from "mongoose";
import type { RecoveryToken as RecoveryTokenEntity } from "@/types/recoveryToken.js";
type RecoveryTokenDocumentBase = Omit<RecoveryTokenEntity, "id" | "createdAt" | "updatedAt" | "expiry"> & {
expiry: Date;
};
interface RecoveryTokenDocument extends RecoveryTokenDocumentBase {
_id: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const RecoveryTokenSchema = new Schema<RecoveryTokenDocument>(
{
email: { type: String, required: true, unique: true },
token: { type: String, required: true },
expiry: { type: Date, default: Date.now, expires: 600 },
},
{ timestamps: true }
);
const RecoveryTokenModel = model<RecoveryTokenDocument>("RecoveryToken", RecoveryTokenSchema);
export type { RecoveryTokenDocument };
export { RecoveryTokenModel };
export default RecoveryTokenModel;