forked from datawhale/whale-town-end
- 添加Users实体定义,包含完整的字段映射和约束 - 实现CreateUserDto数据验证,支持所有字段验证规则 - 创建UsersService服务,提供完整的CRUD操作 - 添加UsersModule模块配置 - 支持用户搜索、统计、批量操作等高级功能
106 lines
2.3 KiB
TypeScript
106 lines
2.3 KiB
TypeScript
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
|
||
|
||
@Entity('users') // 对应数据库表名
|
||
export class Users {
|
||
// id:bigint、主键、非空、唯一、自增
|
||
@PrimaryGeneratedColumn({
|
||
type: 'bigint',
|
||
comment: '主键ID'
|
||
})
|
||
id: bigint;
|
||
|
||
// username:varchar(50)、非空、唯一
|
||
@Column({
|
||
type: 'varchar',
|
||
length: 50,
|
||
nullable: false,
|
||
unique: true,
|
||
comment: '唯一用户名/登录名'
|
||
})
|
||
username: string;
|
||
|
||
// email:varchar(100)、允许空、唯一
|
||
@Column({
|
||
type: 'varchar',
|
||
length: 100,
|
||
nullable: true,
|
||
unique: true,
|
||
comment: '邮箱(用于找回/通知)'
|
||
})
|
||
email: string;
|
||
|
||
// phone:varchar(30)、允许空、唯一
|
||
@Column({
|
||
type: 'varchar',
|
||
length: 30,
|
||
nullable: true,
|
||
unique: true,
|
||
comment: '全球电话号码(用于找回/通知)'
|
||
})
|
||
phone: string;
|
||
|
||
// password_hash:varchar(255)、允许空
|
||
@Column({
|
||
type: 'varchar',
|
||
length: 255,
|
||
nullable: true,
|
||
comment: '密码哈希(OAuth登录为空)'
|
||
})
|
||
password_hash: string;
|
||
|
||
// nickname:varchar(50)、非空
|
||
@Column({
|
||
type: 'varchar',
|
||
length: 50,
|
||
nullable: false,
|
||
comment: '显示昵称(头顶显示)'
|
||
})
|
||
nickname: string;
|
||
|
||
// github_id:varchar(100)、允许空、唯一
|
||
@Column({
|
||
type: 'varchar',
|
||
length: 100,
|
||
nullable: true,
|
||
unique: true,
|
||
comment: 'GitHub OpenID(第三方登录用)'
|
||
})
|
||
github_id: string;
|
||
|
||
// avatar_url:varchar(255)、允许空
|
||
@Column({
|
||
type: 'varchar',
|
||
length: 255,
|
||
nullable: true,
|
||
comment: 'GitHub头像或自定义头像URL'
|
||
})
|
||
avatar_url: string;
|
||
|
||
// role:tinyint、非空、默认1
|
||
@Column({
|
||
type: 'tinyint',
|
||
nullable: false,
|
||
default: 1,
|
||
comment: '角色:1-普通,9-管理员'
|
||
})
|
||
role: number;
|
||
|
||
// created_at:datetime、非空、默认当前时间
|
||
@CreateDateColumn({
|
||
type: 'datetime',
|
||
nullable: false,
|
||
default: () => 'CURRENT_TIMESTAMP',
|
||
comment: '注册时间'
|
||
})
|
||
created_at: Date;
|
||
|
||
// updated_at:datetime、非空、默认当前时间
|
||
@UpdateDateColumn({
|
||
type: 'datetime',
|
||
nullable: false,
|
||
default: () => 'CURRENT_TIMESTAMP',
|
||
onUpdate: 'CURRENT_TIMESTAMP', // 数据库更新时自动刷新时间
|
||
comment: '更新时间'
|
||
})
|
||
updated_at: Date;
|
||
} |