forked from Chatbot/v3-api
first commit v3 initialiazed a temporary repository for darmanet client
This commit is contained in:
76
src/database/model/users-base.model.ts
Normal file
76
src/database/model/users-base.model.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import * as crypto from 'node:crypto';
|
||||
import { Prop, Schema } from '@nestjs/mongoose';
|
||||
import { Role } from 'src/common/types/role.type';
|
||||
|
||||
@Schema()
|
||||
export class UsersBaseModel {
|
||||
@Prop()
|
||||
name: string;
|
||||
|
||||
@Prop()
|
||||
family: string;
|
||||
|
||||
@Prop({ required: true })
|
||||
role: Role;
|
||||
|
||||
@Prop()
|
||||
fatherName: string;
|
||||
|
||||
@Prop()
|
||||
shenasnameseri: string;
|
||||
|
||||
@Prop()
|
||||
shenasnameserial: string;
|
||||
|
||||
@Prop()
|
||||
birthDate: string;
|
||||
|
||||
@Prop()
|
||||
gender: string;
|
||||
|
||||
@Prop({
|
||||
required: false,
|
||||
match: /^[0-9]{11}$/,
|
||||
default: undefined,
|
||||
})
|
||||
mobile: string;
|
||||
|
||||
@Prop()
|
||||
birthday: string;
|
||||
|
||||
@Prop()
|
||||
nationalCode: string;
|
||||
|
||||
@Prop({ match: /^((?!\.)[\w\-_.]*[^.])(@\w+)(\.\w+(\.\w+)?[^.\W])$/ })
|
||||
email: string;
|
||||
|
||||
@Prop()
|
||||
address: string;
|
||||
|
||||
@Prop({
|
||||
default: function () {
|
||||
// Generate 6-digit number or use mobile
|
||||
return (
|
||||
this.mobile || Math.floor(100000 + Math.random() * 900000).toString()
|
||||
);
|
||||
},
|
||||
})
|
||||
username: string;
|
||||
|
||||
@Prop({ type: Date })
|
||||
last_login: Date;
|
||||
|
||||
@Prop({ type: Date, default: Date.now })
|
||||
createdAt: Date;
|
||||
|
||||
@Prop({ type: Date, default: Date.now })
|
||||
updatedAt: Date;
|
||||
|
||||
static validateOtp(otpInput: string, storedOtpHash: string): boolean {
|
||||
const inputOtpHash = crypto
|
||||
.createHash('sha256')
|
||||
.update(otpInput)
|
||||
.digest('hex');
|
||||
return inputOtpHash === storedOtpHash;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user