forked from Chatbot/v3-api
first commit v3 initialiazed a temporary repository for darmanet client
This commit is contained in:
37
src/database/model/user.model.ts
Normal file
37
src/database/model/user.model.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import * as crypto from 'node:crypto';
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { ChatModel } from './chat.model';
|
||||
import { UsersBaseModel } from './users-base.model';
|
||||
|
||||
@Schema({
|
||||
timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' },
|
||||
versionKey: false,
|
||||
collection: 'user',
|
||||
_id: true,
|
||||
})
|
||||
export class UserModel extends UsersBaseModel {
|
||||
@Prop({ default: [] })
|
||||
chat: ChatModel[];
|
||||
|
||||
@Prop({
|
||||
required: false,
|
||||
select: true,
|
||||
set: (otp: string) =>
|
||||
otp ? crypto.createHash('sha256').update(otp).digest('hex') : null,
|
||||
expires: 120, // The OTP will automatically be removed after 120 seconds
|
||||
})
|
||||
otp: string | null;
|
||||
|
||||
@Prop({ type: Date, default: null })
|
||||
otpCreatedAt: Date | null;
|
||||
|
||||
@Prop({ type: Number, default: 0 })
|
||||
otpAttempts: number;
|
||||
}
|
||||
|
||||
export const UserSchema = SchemaFactory.createForClass(UserModel);
|
||||
|
||||
UserSchema.pre('save', function (next) {
|
||||
this.updatedAt = new Date();
|
||||
next();
|
||||
});
|
||||
Reference in New Issue
Block a user