feat: 开发user、auth相关接口,初始化后台管理项目admin

This commit is contained in:
R524809
2025-11-19 17:42:53 +08:00
parent 7acadf191f
commit d195495449
45 changed files with 3016 additions and 101 deletions

View File

@@ -0,0 +1,142 @@
import {
Entity,
Column,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
Index,
} from 'typeorm';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
@Entity('user')
export class User {
@ApiProperty({ description: '用户ID', example: 1 })
@PrimaryGeneratedColumn({ name: 'user_id' })
userId: number;
@ApiPropertyOptional({
description: '微信 openId',
example: 'openid123456',
maxLength: 100,
})
@Column({ name: 'open_id', type: 'varchar', length: 100, nullable: true })
@Index()
openId?: string;
@ApiPropertyOptional({
description: '微信 unionId',
example: 'unionid123456',
maxLength: 100,
})
@Column({ name: 'union_id', type: 'varchar', length: 100, nullable: true })
@Index()
unionId?: string;
@ApiProperty({
description: '用户名',
example: 'john_doe',
maxLength: 100,
})
@Column({ name: 'username', type: 'varchar', length: 100 })
@Index()
username: string;
@ApiProperty({
description: '密码哈希值bcrypt加密',
example: '$2b$10$...',
maxLength: 255,
})
@Column({ name: 'password_hash', type: 'varchar', length: 255 })
passwordHash: string;
@ApiProperty({
description: '邮箱',
example: 'user@example.com',
maxLength: 100,
})
@Column({ name: 'email', type: 'varchar', length: 100 })
@Index()
email: string;
@ApiPropertyOptional({
description: '电话号码',
example: '13800138000',
maxLength: 20,
})
@Column({ name: 'phone', type: 'varchar', length: 20, nullable: true })
@Index()
phone?: string;
@ApiPropertyOptional({
description: '用户昵称',
example: 'John Doe',
maxLength: 100,
})
@Column({ name: 'nickname', type: 'varchar', length: 100, nullable: true })
nickname?: string;
@ApiPropertyOptional({
description: '头像URL',
example: 'https://example.com/avatar.jpg',
maxLength: 255,
})
@Column({
name: 'avatar_url',
type: 'varchar',
length: 255,
nullable: true,
})
avatarUrl?: string;
@ApiProperty({
description: '创建时间',
example: '2024-01-01T00:00:00.000Z',
})
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
@ApiProperty({
description: '更新时间',
example: '2024-01-01T00:00:00.000Z',
})
@UpdateDateColumn({ name: 'updated_at' })
updatedAt: Date;
@ApiPropertyOptional({
description: '最后登录时间',
example: '2024-01-01T00:00:00.000Z',
})
@Column({ name: 'last_login_at', type: 'timestamp', nullable: true })
lastLoginAt?: Date;
@ApiProperty({
description: '用户状态',
example: 'active',
enum: ['active', 'inactive', 'deleted'],
default: 'active',
})
@Column({
name: 'status',
type: 'varchar',
length: 20,
default: 'active',
nullable: false,
})
status: string;
@ApiProperty({
description: '用户角色',
example: 'user',
enum: ['user', 'admin', 'super_admin'],
default: 'user',
})
@Column({
name: 'role',
type: 'varchar',
length: 20,
default: 'user',
nullable: false,
})
@Index()
role: string;
}