mirror of
https://github.com/jakobkordez/ham-reserve.git
synced 2025-08-07 13:47:43 +00:00
Initial commit
This commit is contained in:
46
nest-api/src/users/schemas/user.schema.ts
Normal file
46
nest-api/src/users/schemas/user.schema.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { HydratedDocument, ObjectId } from 'mongoose';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { Role } from 'src/enums/role.enum';
|
||||
|
||||
export type UserDocument = HydratedDocument<User>;
|
||||
|
||||
@Schema()
|
||||
export class User {
|
||||
_id: ObjectId;
|
||||
|
||||
@Prop({ required: true })
|
||||
username: string;
|
||||
|
||||
@Prop({
|
||||
required: true,
|
||||
transform: () => undefined,
|
||||
set: (value: string) => bcrypt.hashSync(value, 10),
|
||||
})
|
||||
password: string;
|
||||
|
||||
@Prop({
|
||||
default: [Role.User],
|
||||
type: [
|
||||
{ type: String, enum: [Role.User.toString(), Role.Admin.toString()] },
|
||||
],
|
||||
})
|
||||
roles: Role[];
|
||||
|
||||
@Prop({ required: true })
|
||||
name: string;
|
||||
|
||||
@Prop()
|
||||
email: string;
|
||||
|
||||
@Prop()
|
||||
phone: string;
|
||||
|
||||
@Prop({
|
||||
transform: () => undefined,
|
||||
set: (value: string) => bcrypt.hashSync(value, 10),
|
||||
})
|
||||
auth: string;
|
||||
}
|
||||
|
||||
export const UserSchema = SchemaFactory.createForClass(User);
|
Reference in New Issue
Block a user