82 lines
2.0 KiB
TypeScript
82 lines
2.0 KiB
TypeScript
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|
import { ObjectType, Field, ID } from '@nestjs/graphql';
|
|
import { Document, Types } from 'mongoose';
|
|
import { Base } from '@/models/base.model';
|
|
import { Person } from '@/models/person.model';
|
|
import { UserType } from '@/models/user-type.model';
|
|
|
|
@ObjectType()
|
|
export class CollectionTokenItem {
|
|
|
|
@Field()
|
|
@Prop({ required: true })
|
|
prefix: string;
|
|
|
|
@Field()
|
|
@Prop({ required: true })
|
|
token: string;
|
|
}
|
|
|
|
@ObjectType()
|
|
export class CollectionToken {
|
|
|
|
@Field(() => [CollectionTokenItem])
|
|
@Prop({ type: [CollectionTokenItem], default: [] })
|
|
tokens: CollectionTokenItem[];
|
|
|
|
@Field()
|
|
@Prop({ required: true, default: '' })
|
|
default: string;
|
|
}
|
|
|
|
@ObjectType()
|
|
@Schema({ timestamps: true })
|
|
export class User extends Base {
|
|
|
|
@Field(() => ID)
|
|
_id: string;
|
|
|
|
@Field({ nullable: true })
|
|
@Prop({ default: () => new Date(Date.now() + 30 * 24 * 60 * 60 * 1000) })
|
|
expiresAt?: Date;
|
|
|
|
@Field({ nullable: true })
|
|
@Prop()
|
|
resetToken?: string;
|
|
|
|
@Field()
|
|
@Prop({ required: true })
|
|
password: string;
|
|
|
|
@Field(() => [String], { nullable: 'itemsAndList' })
|
|
@Prop({ type: [String], default: [], validate: [(val: string[]) => val.length <= 3, 'History can have max 3 items'] })
|
|
history?: string[];
|
|
|
|
@Field()
|
|
@Prop({ required: true })
|
|
tag: string;
|
|
|
|
@Field()
|
|
@Prop({ required: true, unique: true })
|
|
email: string;
|
|
|
|
@Field()
|
|
@Prop({ required: true, unique: true })
|
|
phone: string;
|
|
|
|
@Field(() => CollectionToken)
|
|
@Prop({ type: CollectionToken, default: () => ({ tokens: [], default: '' }) })
|
|
collectionTokens: CollectionToken;
|
|
|
|
@Field(() => ID)
|
|
@Prop({ type: Types.ObjectId, ref: Person.name, required: true })
|
|
person: Types.ObjectId;
|
|
|
|
@Field(() => ID, { nullable: true })
|
|
@Prop({ type: Types.ObjectId, ref: UserType.name })
|
|
type?: Types.ObjectId;
|
|
}
|
|
|
|
export type UserDocument = User & Document;
|
|
export const UserSchema = SchemaFactory.createForClass(User);
|