forked from Yara724/api
Added registrar + fixed sign bug in car-body flow
This commit is contained in:
40
src/users/entities/db-service/registrar.db.service.ts
Normal file
40
src/users/entities/db-service/registrar.db.service.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model, Types } from "mongoose";
|
||||
import { RegistrarModel } from "../schema/registrar.schema";
|
||||
|
||||
@Injectable()
|
||||
export class RegistrarDbService {
|
||||
constructor(
|
||||
@InjectModel(RegistrarModel.name)
|
||||
private readonly registrarModel: Model<RegistrarModel>,
|
||||
) {}
|
||||
|
||||
async create(
|
||||
user: Partial<RegistrarModel> & { password: string },
|
||||
): Promise<RegistrarModel> {
|
||||
return this.registrarModel.create(user);
|
||||
}
|
||||
|
||||
async findOne(
|
||||
filter: FilterQuery<RegistrarModel>,
|
||||
): Promise<RegistrarModel | null> {
|
||||
return this.registrarModel.findOne(filter);
|
||||
}
|
||||
|
||||
async findOneAndUpdate(
|
||||
filter: FilterQuery<RegistrarModel>,
|
||||
update: any,
|
||||
): Promise<RegistrarModel | null> {
|
||||
return this.registrarModel.findOneAndUpdate(filter, update, { new: true });
|
||||
}
|
||||
|
||||
async updateOne(filter: FilterQuery<RegistrarModel>, update: any) {
|
||||
return this.registrarModel.updateOne(filter, update);
|
||||
}
|
||||
|
||||
async findById(userId: string): Promise<RegistrarModel | null> {
|
||||
return this.registrarModel.findOne({ _id: new Types.ObjectId(userId) });
|
||||
}
|
||||
}
|
||||
|
||||
38
src/users/entities/schema/registrar.schema.ts
Normal file
38
src/users/entities/schema/registrar.schema.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
|
||||
import { Types } from "mongoose";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
|
||||
@Schema({
|
||||
collection: "registrar",
|
||||
versionKey: false,
|
||||
timestamps: true,
|
||||
})
|
||||
export class RegistrarModel {
|
||||
_id?: Types.ObjectId;
|
||||
|
||||
@Prop({ type: "string", unique: true })
|
||||
email: string;
|
||||
|
||||
@Prop({ type: "string" })
|
||||
username: string;
|
||||
|
||||
@Prop({ required: true })
|
||||
password: string;
|
||||
|
||||
@Prop({ type: Types.ObjectId, required: true, index: true })
|
||||
clientKey: Types.ObjectId;
|
||||
|
||||
@Prop({ default: RoleEnum.REGISTRAR })
|
||||
role: RoleEnum;
|
||||
|
||||
@Prop({ type: "string", default: "" })
|
||||
otp: string;
|
||||
}
|
||||
|
||||
export const RegistrarDbSchema = SchemaFactory.createForClass(RegistrarModel);
|
||||
|
||||
RegistrarDbSchema.pre("save", function (next) {
|
||||
if (!this.username) this.username = this.email;
|
||||
next();
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import { OtpModule } from "src/utils/otp/otp.module";
|
||||
import { ExpertDbService } from "./entities/db-service/expert.db.service";
|
||||
import { FieldExpertDbService } from "./entities/db-service/field-expert.db.service";
|
||||
import { InsurerExpertDbService } from "./entities/db-service/insurer-expert.db.service";
|
||||
import { RegistrarDbService } from "./entities/db-service/registrar.db.service";
|
||||
import { UserDbService } from "./entities/db-service/user.db.service";
|
||||
import {
|
||||
DamageExpertDbSchema,
|
||||
@@ -21,6 +22,10 @@ import {
|
||||
InsurerExpertDbSchema,
|
||||
InsurerExpertModel,
|
||||
} from "./entities/schema/insurer-expert.schema";
|
||||
import {
|
||||
RegistrarDbSchema,
|
||||
RegistrarModel,
|
||||
} from "./entities/schema/registrar.schema";
|
||||
import { UserModel, UserDbSchema } from "./entities/schema/user.schema";
|
||||
|
||||
@Module({
|
||||
@@ -31,6 +36,7 @@ import { UserModel, UserDbSchema } from "./entities/schema/user.schema";
|
||||
{ name: ExpertModel.name, schema: ExpertDbSchema },
|
||||
{ name: FieldExpertModel.name, schema: FieldExpertDbSchema },
|
||||
{ name: InsurerExpertModel.name, schema: InsurerExpertDbSchema },
|
||||
{ name: RegistrarModel.name, schema: RegistrarDbSchema },
|
||||
]),
|
||||
OtpModule,
|
||||
HashModule,
|
||||
@@ -42,6 +48,7 @@ import { UserModel, UserDbSchema } from "./entities/schema/user.schema";
|
||||
DamageExpertDbService,
|
||||
FieldExpertDbService,
|
||||
InsurerExpertDbService,
|
||||
RegistrarDbService,
|
||||
],
|
||||
exports: [
|
||||
UserDbService,
|
||||
@@ -49,6 +56,7 @@ import { UserModel, UserDbSchema } from "./entities/schema/user.schema";
|
||||
DamageExpertDbService,
|
||||
FieldExpertDbService,
|
||||
InsurerExpertDbService,
|
||||
RegistrarDbService,
|
||||
],
|
||||
})
|
||||
export class UsersModule {}
|
||||
|
||||
Reference in New Issue
Block a user