import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; import { HydratedDocument } from "mongoose"; @Schema({ collection: "captcha-challenges", timestamps: true, versionKey: false, }) export class CaptchaChallenge { @Prop({ required: true, unique: true, index: true }) captchaId: string; @Prop() answerHash?: string; @Prop({ required: true }) image: string; @Prop({ required: true, index: true }) expiresAt: number; /** Mongo TTL — document removed shortly after this time. */ @Prop({ required: true, expires: 0 }) expireAt: Date; @Prop({ default: null }) usedAt?: Date | null; } export type CaptchaChallengeDocument = HydratedDocument; export const CaptchaChallengeSchema = SchemaFactory.createForClass(CaptchaChallenge);