forked from Shared/esg
90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
|
import { ClientType } from '../../common/enums/client-type.enum';
|
|
import { Role } from '../../common/enums/role.enum';
|
|
|
|
/**
|
|
* Unified user model — internal admins and external API clients share one table.
|
|
* Designed for future extensions: API keys, HMAC, IP whitelist, permissions, multi-tenant.
|
|
*/
|
|
@Entity('users')
|
|
@Index(['role', 'isActive'])
|
|
@Index(['clientType', 'appName'])
|
|
export class User {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Column({ type: 'text' })
|
|
fullName!: string;
|
|
|
|
@Index({ unique: true })
|
|
@Column({ type: 'text' })
|
|
username!: string;
|
|
|
|
@Index({ unique: true })
|
|
@Column({ type: 'text' })
|
|
email!: string;
|
|
|
|
@Column({ type: 'text', nullable: true })
|
|
mobile?: string | null;
|
|
|
|
@Column({ type: 'text', select: false })
|
|
password!: string;
|
|
|
|
@Index()
|
|
@Column({ type: 'text' })
|
|
role!: Role;
|
|
|
|
@Index()
|
|
@Column({ type: 'text' })
|
|
clientType!: ClientType;
|
|
|
|
@Column({ type: 'text', default: '' })
|
|
appName!: string;
|
|
|
|
@Column({ type: 'text', default: '' })
|
|
clientName!: string;
|
|
|
|
@Column({ type: 'boolean', default: true })
|
|
isActive!: boolean;
|
|
|
|
@Column({ type: 'boolean', default: false })
|
|
isBlocked!: boolean;
|
|
|
|
/** Future: machine-to-machine auth without JWT. */
|
|
@Column({ type: 'text', nullable: true, select: false })
|
|
apiKey?: string | null;
|
|
|
|
@Column({ type: 'text', array: true, default: () => "'{}'" })
|
|
allowedInquiries!: string[];
|
|
|
|
@Column({ type: 'int', default: 60 })
|
|
requestLimitPerMinute!: number;
|
|
|
|
@Column({ type: 'int', default: 10000 })
|
|
requestLimitPerDay!: number;
|
|
|
|
@Column({ type: 'int', default: 0 })
|
|
totalRequests!: number;
|
|
|
|
@Column({ type: 'timestamptz', nullable: true })
|
|
lastLoginAt?: Date | null;
|
|
|
|
@Column({ type: 'timestamptz', nullable: true })
|
|
passwordChangedAt?: Date | null;
|
|
|
|
@Column({ type: 'uuid', nullable: true })
|
|
createdBy?: string | null;
|
|
|
|
@Column({ type: 'text', nullable: true, select: false })
|
|
refreshToken?: string | null;
|
|
|
|
@Column({ type: 'jsonb', default: () => "'{}'::jsonb" })
|
|
metadata!: Record<string, unknown>;
|
|
|
|
@CreateDateColumn({ type: 'timestamptz' })
|
|
createdAt!: Date;
|
|
|
|
@UpdateDateColumn({ type: 'timestamptz' })
|
|
updatedAt!: Date;
|
|
}
|