| 1 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose' |
| 2 | import { AccountType } from '@yikart/common' |
| 3 | import { Schema as MongooseSchema } from 'mongoose' |
| 4 | import { DEFAULT_SCHEMA_OPTIONS } from '../channel-db.constants' |
| 5 | import { AccountStatus } from '../enums' |
| 6 | import { BaseTemp } from './time.tamp' |
| 7 | |
| 8 | @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'account' }) |
| 9 | export class Account extends BaseTemp { |
| 10 | @Prop({ type: MongooseSchema.Types.String }) |
| 11 | _id: string |
| 12 | |
| 13 | id: string |
| 14 | |
| 15 | @Prop({ |
| 16 | required: false, |
| 17 | type: String, |
| 18 | }) |
| 19 | userId?: string |
| 20 | |
| 21 | @Prop({ |
| 22 | required: true, |
| 23 | enum: AccountType, |
| 24 | }) |
| 25 | type: AccountType |
| 26 | |
| 27 | @Prop({ |
| 28 | required: true, // 平台账户的唯一ID |
| 29 | }) |
| 30 | uid: string |
| 31 | |
| 32 | @Prop({ |
| 33 | required: false, // 部分平台的补充ID |
| 34 | }) |
| 35 | account: string |
| 36 | |
| 37 | @Prop({ |
| 38 | required: false, |
| 39 | type: Date, |
| 40 | }) |
| 41 | loginTime?: Date |
| 42 | |
| 43 | @Prop({ |
| 44 | required: false, |
| 45 | }) |
| 46 | avatar?: string |
| 47 | |
| 48 | @Prop({ |
| 49 | required: true, |
| 50 | }) |
| 51 | nickname: string |
| 52 | |
| 53 | @Prop({ |
| 54 | required: true, |
| 55 | default: AccountStatus.NORMAL, |
| 56 | }) |
| 57 | status: AccountStatus // 登录状态,用于判断是否失效 |
| 58 | } |
| 59 | |
| 60 | export const AccountSchema = SchemaFactory.createForClass(Account) |
| 61 | AccountSchema.index( |
| 62 | { type: 1, uid: 1, account: 1 }, |
| 63 | { |
| 64 | unique: true, |
| 65 | name: 'type_1_uid_1_account_1', |
| 66 | }, |
| 67 | ) |
| 68 |