From 4d21045303b2baa621c14a3392ee6fae4630ac01 Mon Sep 17 00:00:00 2001 From: tone <3341154833@qq.com> Date: Wed, 7 May 2025 13:36:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4user=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/user/entities/user.entity.ts | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tone-page-server/src/user/entities/user.entity.ts diff --git a/tone-page-server/src/user/entities/user.entity.ts b/tone-page-server/src/user/entities/user.entity.ts new file mode 100644 index 0000000..c191ba5 --- /dev/null +++ b/tone-page-server/src/user/entities/user.entity.ts @@ -0,0 +1,55 @@ +import { BeforeInsert, Column, CreateDateColumn, DeleteDateColumn, Entity, In, Index, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"; +import { v4 as uuidv4 } from 'uuid'; + +@Entity() +export class User { + @PrimaryGeneratedColumn() + id: number; + + @Column('uuid', { unique: true, default: () => 'gen_random_uuid()' }) + @Index({ unique: true }) + userId: string; + + @Column({ length: 32 }) + @Index({ unique: true }) + username: string; + + @Column({ length: 30 }) + nickname: string; + + @BeforeInsert() + generateDefaults() { + if (!this.username) { + this.username = `user_${uuidv4().replace(/-/g, '').slice(0, 27)}`; + } + if (!this.nickname) { + this.nickname = `用户_${uuidv4().replace(/-/g, '').slice(0, 8)}`; + } + } + + @Column({ nullable: true, type: 'char', length: 32 }) + salt: string; + + @Column({ nullable: true, type: 'char', length: 64 }) + password_hash: string; + + @Column({ nullable: true, length: 254 })// RFC 5321 + @Index({ unique: true }) + email: string; + + @Column({ nullable: true, length: 20 })// China Mainland + @Index({ unique: true }) + phone: string; + + @Column({ nullable: true }) + avatar: string; + + @CreateDateColumn({ precision: 3 }) + createdAt: Date; + + @UpdateDateColumn({ precision: 3 }) + updatedAt: Date; + + @DeleteDateColumn({ nullable: true, precision: 3 }) + deletedAt: Date; +} \ No newline at end of file