Files
whale-town-end/src/core/db/users/users.entity.ts
moyin 418ecaa303 feat:实现完整的用户管理系统
- 添加Users实体定义,包含完整的字段映射和约束
- 实现CreateUserDto数据验证,支持所有字段验证规则
- 创建UsersService服务,提供完整的CRUD操作
- 添加UsersModule模块配置
- 支持用户搜索、统计、批量操作等高级功能
2025-12-17 11:03:17 +08:00

106 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
@Entity('users') // 对应数据库表名
export class Users {
// idbigint、主键、非空、唯一、自增
@PrimaryGeneratedColumn({
type: 'bigint',
comment: '主键ID'
})
id: bigint;
// usernamevarchar(50)、非空、唯一
@Column({
type: 'varchar',
length: 50,
nullable: false,
unique: true,
comment: '唯一用户名/登录名'
})
username: string;
// emailvarchar(100)、允许空、唯一
@Column({
type: 'varchar',
length: 100,
nullable: true,
unique: true,
comment: '邮箱(用于找回/通知)'
})
email: string;
// phonevarchar(30)、允许空、唯一
@Column({
type: 'varchar',
length: 30,
nullable: true,
unique: true,
comment: '全球电话号码(用于找回/通知)'
})
phone: string;
// password_hashvarchar(255)、允许空
@Column({
type: 'varchar',
length: 255,
nullable: true,
comment: '密码哈希OAuth登录为空'
})
password_hash: string;
// nicknamevarchar(50)、非空
@Column({
type: 'varchar',
length: 50,
nullable: false,
comment: '显示昵称(头顶显示)'
})
nickname: string;
// github_idvarchar(100)、允许空、唯一
@Column({
type: 'varchar',
length: 100,
nullable: true,
unique: true,
comment: 'GitHub OpenID第三方登录用'
})
github_id: string;
// avatar_urlvarchar(255)、允许空
@Column({
type: 'varchar',
length: 255,
nullable: true,
comment: 'GitHub头像或自定义头像URL'
})
avatar_url: string;
// roletinyint、非空、默认1
@Column({
type: 'tinyint',
nullable: false,
default: 1,
comment: '角色1-普通9-管理员'
})
role: number;
// created_atdatetime、非空、默认当前时间
@CreateDateColumn({
type: 'datetime',
nullable: false,
default: () => 'CURRENT_TIMESTAMP',
comment: '注册时间'
})
created_at: Date;
// updated_atdatetime、非空、默认当前时间
@UpdateDateColumn({
type: 'datetime',
nullable: false,
default: () => 'CURRENT_TIMESTAMP',
onUpdate: 'CURRENT_TIMESTAMP', // 数据库更新时自动刷新时间
comment: '更新时间'
})
updated_at: Date;
}