forked from Chatbot/v3-api
78 lines
1.4 KiB
TypeScript
78 lines
1.4 KiB
TypeScript
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;
|
|
|
|
/** System role (`admin`/`expert`/…) or a custom ACL role name. */
|
|
@Prop({ required: true, type: String })
|
|
role: Role | string;
|
|
|
|
@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;
|
|
}
|
|
}
|