import { Injectable } from "@nestjs/common"; import { InjectModel } from "@nestjs/mongoose"; import { Model } from "mongoose"; import { CaptchaChallenge, CaptchaChallengeDocument, } from "../schema/captcha-challenge.schema"; @Injectable() export class CaptchaChallengeDbService { constructor( @InjectModel(CaptchaChallenge.name) private readonly captchaChallengeModel: Model, ) {} create(data: CaptchaChallenge): Promise { return this.captchaChallengeModel.create(data); } findByCaptchaId( captchaId: string, ): Promise { return this.captchaChallengeModel.findOne({ captchaId }); } markUsed(captchaId: string): Promise { return this.captchaChallengeModel.findOneAndUpdate( { captchaId, usedAt: null }, { $set: { usedAt: new Date() } }, { new: true }, ); } }