| 1 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose' |
| 2 | import { UserStatus, UserType } from '../enums' |
| 3 | import { DEFAULT_SCHEMA_OPTIONS } from '../mongodb.constants' |
| 4 | import { WithTimestampSchema } from './timestamp.schema' |
| 5 | |
| 6 | @Schema({ |
| 7 | toJSON: { virtuals: true }, |
| 8 | toObject: { virtuals: true }, |
| 9 | }) |
| 10 | export class UserAiItemInfo { |
| 11 | @Prop({ required: true }) |
| 12 | defaultModel: string |
| 13 | |
| 14 | @Prop({ |
| 15 | required: false, |
| 16 | default: {}, |
| 17 | type: Object, |
| 18 | }) |
| 19 | option?: Record<string, any> |
| 20 | } |
| 21 | |
| 22 | @Schema({ |
| 23 | toJSON: { virtuals: true }, |
| 24 | toObject: { virtuals: true }, |
| 25 | }) |
| 26 | export class UserAiInfo { |
| 27 | @Prop({ |
| 28 | required: false, |
| 29 | type: UserAiItemInfo, |
| 30 | }) |
| 31 | image?: UserAiItemInfo |
| 32 | |
| 33 | @Prop({ |
| 34 | required: false, |
| 35 | type: UserAiItemInfo, |
| 36 | }) |
| 37 | edit?: UserAiItemInfo |
| 38 | |
| 39 | @Prop({ |
| 40 | required: false, |
| 41 | type: UserAiItemInfo, |
| 42 | }) |
| 43 | video?: UserAiItemInfo |
| 44 | |
| 45 | @Prop({ |
| 46 | required: false, |
| 47 | type: UserAiItemInfo, |
| 48 | }) |
| 49 | agent?: UserAiItemInfo |
| 50 | } |
| 51 | |
| 52 | @Schema({ _id: false }) |
| 53 | export class UserLocation { |
| 54 | @Prop({ type: Number, required: false }) |
| 55 | lat?: number // 纬度 |
| 56 | |
| 57 | @Prop({ type: Number, required: false }) |
| 58 | lng?: number // 经度 |
| 59 | |
| 60 | @Prop({ type: String, required: false }) |
| 61 | country?: string // 国家名称 |
| 62 | |
| 63 | @Prop({ type: String, required: false }) |
| 64 | countryCode?: string // 国家代码 |
| 65 | |
| 66 | @Prop({ type: String, required: false }) |
| 67 | city?: string // 城市名称 |
| 68 | |
| 69 | @Prop({ type: String, required: false }) |
| 70 | cityCode?: string // 城市代码 |
| 71 | |
| 72 | @Prop({ type: String, required: false }) |
| 73 | district?: string // 区/县名称 |
| 74 | |
| 75 | @Prop({ type: String, required: false }) |
| 76 | districtCode?: string // 区/县代码 |
| 77 | } |
| 78 | |
| 79 | export class UserStorage { |
| 80 | @Prop({ |
| 81 | required: true, |
| 82 | default: 500 * 1024 * 1024, |
| 83 | }) |
| 84 | total: number // Total Storage (Bytes) |
| 85 | |
| 86 | @Prop({ required: false }) |
| 87 | expiredAt?: Date |
| 88 | } |
| 89 | |
| 90 | @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'user' }) |
| 91 | export class User extends WithTimestampSchema { |
| 92 | id: string |
| 93 | |
| 94 | @Prop({ |
| 95 | required: true, |
| 96 | default: '', |
| 97 | }) |
| 98 | name: string |
| 99 | |
| 100 | @Prop({ |
| 101 | required: false, |
| 102 | index: true, |
| 103 | }) |
| 104 | mail?: string |
| 105 | |
| 106 | @Prop({ |
| 107 | required: false, |
| 108 | }) |
| 109 | avatar?: string |
| 110 | |
| 111 | @Prop({ |
| 112 | required: true, |
| 113 | enum: UserStatus, |
| 114 | default: UserStatus.OPEN, |
| 115 | }) |
| 116 | status: UserStatus |
| 117 | |
| 118 | @Prop({ |
| 119 | required: true, |
| 120 | enum: UserType, |
| 121 | default: UserType.CREATOR, |
| 122 | index: true, |
| 123 | }) |
| 124 | userType: UserType |
| 125 | |
| 126 | // Is Deleted |
| 127 | @Prop({ |
| 128 | required: true, |
| 129 | default: false, |
| 130 | index: true, |
| 131 | }) |
| 132 | isDelete: boolean |
| 133 | |
| 134 | @Prop({ |
| 135 | required: true, |
| 136 | default: 0, |
| 137 | }) |
| 138 | usedStorage: number // 已用存储(Bytes) |
| 139 | |
| 140 | @Prop({ |
| 141 | type: UserStorage, |
| 142 | required: true, |
| 143 | default: { |
| 144 | total: 500 * 1024 * 1024, |
| 145 | }, |
| 146 | }) |
| 147 | storage: UserStorage |
| 148 | |
| 149 | @Prop({ |
| 150 | required: false, |
| 151 | type: UserAiInfo, |
| 152 | }) |
| 153 | aiInfo?: UserAiInfo |
| 154 | |
| 155 | @Prop({ required: false, type: UserLocation }) |
| 156 | location?: UserLocation // 用户位置信息 |
| 157 | |
| 158 | @Prop({ type: String, required: false, default: 'en-US' }) |
| 159 | locale?: string // 用户语言偏好 (en-US | zh-CN) |
| 160 | } |
| 161 | |
| 162 | export const UserSchema = SchemaFactory.createForClass(User) |
| 163 |