forked from Yara724/api
34 lines
948 B
TypeScript
34 lines
948 B
TypeScript
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<CaptchaChallengeDocument>,
|
|
) {}
|
|
|
|
create(data: CaptchaChallenge): Promise<CaptchaChallengeDocument> {
|
|
return this.captchaChallengeModel.create(data);
|
|
}
|
|
|
|
findByCaptchaId(
|
|
captchaId: string,
|
|
): Promise<CaptchaChallengeDocument | null> {
|
|
return this.captchaChallengeModel.findOne({ captchaId });
|
|
}
|
|
|
|
markUsed(captchaId: string): Promise<CaptchaChallengeDocument | null> {
|
|
return this.captchaChallengeModel.findOneAndUpdate(
|
|
{ captchaId, usedAt: null },
|
|
{ $set: { usedAt: new Date() } },
|
|
{ new: true },
|
|
);
|
|
}
|
|
}
|