forked from Yara724/api
39 lines
852 B
TypeScript
39 lines
852 B
TypeScript
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();
|
|
});
|
|
|