返回 AiToEarn
user.schema.ts
根目录 / project / aitoearn-electron / server / src / db / schema / user.schema.ts
1 /*
2 * @Author: nevin
3 * @Date: 2022-11-16 22:04:18
4 * @LastEditTime: 2025-05-06 15:50:05
5 * @LastEditors: nevin
6 * @Description: 用户
7 */
8 import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
9 import { TimeTemp } from './time.tamp';
10 export enum UserStatus {
11 STOP = 0,
12 OPEN = 1,
13 DELETE = -1,
14 }
15
16 export enum EarnInfoStatus {
17 CLOSE = 0,
18 OPEN = 1,
19 }
20
21 @Schema({
22 toJSON: { virtuals: true },
23 toObject: { virtuals: true },
24 })
25 export class UserBackData {
26 @Prop({
27 required: false,
28 })
29 phone?: string;
30
31 @Prop({ required: false })
32 wxOpenid?: string;
33
34 @Prop({ required: false })
35 wxUnionid?: string;
36 }
37
38 @Schema({
39 toJSON: { virtuals: true },
40 toObject: { virtuals: true },
41 })
42 export class UserEarnInfo {
43 @Prop({
44 required: true,
45 enum: EarnInfoStatus,
46 default: EarnInfoStatus.OPEN,
47 })
48 status: EarnInfoStatus;
49
50 @Prop({ required: true })
51 cycleInterval: number;
52 }
53
54 @Schema({
55 toJSON: { virtuals: true },
56 toObject: { virtuals: true },
57 })
58 export class GoogleAccount {
59 @Prop({ required: true })
60 googleId: string;
61
62 @Prop({ required: true })
63 email: string;
64
65 @Prop()
66 refreshToken: string;
67
68 @Prop()
69 expiresAt?: number;
70 }
71
72 @Schema({
73 collection: 'user',
74 versionKey: false,
75 toJSON: { virtuals: true },
76 toObject: { virtuals: true },
77 timestamps: false,
78 })
79 export class User extends TimeTemp {
80 id: string;
81
82 @Prop({
83 required: true,
84 default: '',
85 })
86 name: string;
87
88 @Prop({
89 required: false,
90 index: true,
91 unique: true,
92 })
93 mail?: string;
94
95 @Prop({ type: Object, required: false, default: {} })
96 googleAccount?: GoogleAccount;
97
98 @Prop({
99 required: false,
100 index: true,
101 unique: true,
102 })
103 googleId?: string;
104
105 @Prop({
106 required: false,
107 })
108 phone?: string;
109
110 @Prop({
111 required: false,
112 })
113 password?: string;
114
115 @Prop({
116 required: false,
117 })
118 salt?: string;
119
120 @Prop({
121 required: true,
122 enum: UserStatus,
123 default: UserStatus.OPEN,
124 })
125 status: UserStatus;
126
127 @Prop({ required: false })
128 wxOpenid?: string;
129
130 @Prop({ required: false })
131 wxUnionid?: string;
132
133 @Prop({ required: false })
134 popularizeCode?: string; // 我的推广码
135
136 @Prop({ required: false })
137 inviteUserId?: string; // 邀请人用户ID
138
139 @Prop({ required: false })
140 inviteCode?: string; // 我填写的邀请码
141
142 @Prop({ type: Object, required: false, default: {} })
143 backData?: UserBackData;
144
145 @Prop({ type: Object, required: false, default: {} })
146 earnInfo?: UserEarnInfo;
147 }
148
149 export const UserSchema = SchemaFactory.createForClass(User);
150
150 lines TYPESCRIPT