| 1 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose' |
| 2 | import { DEFAULT_SCHEMA_OPTIONS } from '../mongodb.constants' |
| 3 | import { WithTimestampSchema } from './timestamp.schema' |
| 4 | |
| 5 | @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'accountGroup' }) |
| 6 | export class AccountGroup extends WithTimestampSchema { |
| 7 | id: string |
| 8 | |
| 9 | @Prop({ |
| 10 | required: true, |
| 11 | type: String, |
| 12 | }) |
| 13 | userId: string |
| 14 | |
| 15 | // 是否为默认用户组 |
| 16 | @Prop({ |
| 17 | required: true, |
| 18 | type: Boolean, |
| 19 | default: false, |
| 20 | }) |
| 21 | isDefault: boolean |
| 22 | |
| 23 | @Prop({ |
| 24 | required: false, |
| 25 | type: String, |
| 26 | }) |
| 27 | ip?: string |
| 28 | |
| 29 | @Prop({ |
| 30 | required: false, |
| 31 | type: String, |
| 32 | }) |
| 33 | location?: string |
| 34 | |
| 35 | @Prop({ |
| 36 | required: false, |
| 37 | type: String, |
| 38 | }) |
| 39 | countryCode?: string |
| 40 | |
| 41 | // 代理IP |
| 42 | @Prop({ |
| 43 | required: false, |
| 44 | type: String, |
| 45 | default: '', |
| 46 | }) |
| 47 | proxyIp: string |
| 48 | |
| 49 | // 组名称 |
| 50 | @Prop({ |
| 51 | required: true, |
| 52 | type: String, |
| 53 | }) |
| 54 | name: string |
| 55 | |
| 56 | // json 指纹浏览器配置 |
| 57 | @Prop({ |
| 58 | required: false, |
| 59 | type: Object, |
| 60 | }) |
| 61 | browserConfig?: Record<string, any> |
| 62 | |
| 63 | // 组排序 |
| 64 | @Prop({ |
| 65 | required: true, |
| 66 | type: Number, |
| 67 | default: 1, |
| 68 | }) |
| 69 | rank: number |
| 70 | } |
| 71 | |
| 72 | export const AccountGroupSchema = SchemaFactory.createForClass(AccountGroup) |
| 73 | AccountGroupSchema.index( |
| 74 | { userId: 1, isDefault: 1 }, |
| 75 | { |
| 76 | unique: true, |
| 77 | name: 'userId_1_isDefault_1_default', |
| 78 | partialFilterExpression: { isDefault: true }, |
| 79 | }, |
| 80 | ) |
| 81 |