1
0
forked from Yara724/api

Fixed mismatched userId on field expert for claim

This commit is contained in:
SepehrYahyaee
2026-06-20 11:53:18 +03:30
parent d355771518
commit 5a89a0ff16
26 changed files with 144 additions and 414 deletions

View File

@@ -1,7 +1,7 @@
import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { User } from "../schemas";
import { Model } from "mongoose";
import { Otp, User } from "../schemas";
@Injectable()
export class UserRepository {
@@ -10,7 +10,9 @@ export class UserRepository {
private readonly model: Model<User>,
) {}
async addUser() {}
async create(cellphoneNumber: string): Promise<User> {
return this.model.create({ cellphoneNumber });
}
async retrieveByCellPhoneNumber(
cellphoneNumber: string,
@@ -19,4 +21,19 @@ export class UserRepository {
cellphoneNumber,
});
}
async saveOtp(cellphoneNumber: string, otp: Otp): Promise<void> {
await this.model.updateOne({ cellphoneNumber }, { $set: { otp } });
}
async clearOtp(cellphoneNumber: string): Promise<void> {
await this.model.updateOne({ cellphoneNumber }, { $unset: { otp: "" } });
}
async incrementOtpAttempts(cellphoneNumber: string): Promise<void> {
await this.model.updateOne(
{ cellphoneNumber },
{ $inc: { "otp.attempts": 1 } },
);
}
}

View File

@@ -8,17 +8,14 @@ export class Otp {
@Prop()
hash: string;
@Prop()
salt: string;
@Prop()
expiresAt: Date;
@Prop({ default: 0 })
attempts: number;
attempts?: number;
@Prop({ default: Date.now })
generatedAt: Date;
generatedAt?: Date;
}
export const OtpSchema = SchemaFactory.createForClass(Otp);

View File

@@ -1,8 +1,17 @@
import { Module } from "@nestjs/common";
import { MongooseModule } from "@nestjs/mongoose";
import { UserRepository } from "./repositories";
import { User, UserSchema } from "./schemas";
@Module({
imports: [],
imports: [
MongooseModule.forFeature([
{
name: User.name,
schema: UserSchema,
},
]),
],
controllers: [],
providers: [UserRepository],
exports: [UserRepository],