forked from Yara724/api
Fixed mismatched userId on field expert for claim
This commit is contained in:
@@ -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 } },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user