72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
|
import { TimestampedEntity } from './timestamped.entity';
|
|
|
|
export enum UserStatus {
|
|
ACTIVE = 'ACTIVE',
|
|
INACTIVE = 'INACTIVE',
|
|
}
|
|
|
|
@Entity({ name: 'users' })
|
|
@Index('idx_users_status', ['status'])
|
|
@Index('idx_users_locked_until', ['lockedUntil'])
|
|
export class User extends TimestampedEntity {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Column({ type: 'varchar', length: 80 })
|
|
username!: string;
|
|
|
|
@Column({ type: 'varchar', length: 320, nullable: true })
|
|
email!: string | null;
|
|
|
|
@Column({ type: 'varchar', length: 32, nullable: true })
|
|
dni!: string | null;
|
|
|
|
@Column({ type: 'varchar', length: 40, nullable: true })
|
|
phone!: string | null;
|
|
|
|
@Column({ name: 'job_title', type: 'varchar', length: 160, nullable: true })
|
|
jobTitle!: string | null;
|
|
|
|
@Column({ name: 'employee_number', type: 'varchar', length: 80, nullable: true })
|
|
employeeNumber!: string | null;
|
|
|
|
@Column({ name: 'password_hash', type: 'text', select: false })
|
|
passwordHash!: string;
|
|
|
|
@Column({ name: 'first_name', type: 'varchar', length: 120 })
|
|
firstName!: string;
|
|
|
|
@Column({ name: 'last_name', type: 'varchar', length: 120 })
|
|
lastName!: string;
|
|
|
|
@Column({
|
|
type: 'enum',
|
|
enum: UserStatus,
|
|
enumName: 'user_status',
|
|
default: UserStatus.ACTIVE,
|
|
})
|
|
status!: UserStatus;
|
|
|
|
@Column({ name: 'must_change_password', type: 'boolean', default: true })
|
|
mustChangePassword!: boolean;
|
|
|
|
@Column({ name: 'failed_login_attempts', type: 'integer', default: 0 })
|
|
failedLoginAttempts!: number;
|
|
|
|
@Column({ name: 'locked_until', type: 'timestamptz', nullable: true })
|
|
lockedUntil!: Date | null;
|
|
|
|
@Column({ name: 'last_login_at', type: 'timestamptz', nullable: true })
|
|
lastLoginAt!: Date | null;
|
|
|
|
@Column({ name: 'password_changed_at', type: 'timestamptz', nullable: true })
|
|
passwordChangedAt!: Date | null;
|
|
|
|
@Column({ name: 'created_by', type: 'uuid', nullable: true })
|
|
createdBy!: string | null;
|
|
|
|
@Column({ name: 'updated_by', type: 'uuid', nullable: true })
|
|
updatedBy!: string | null;
|
|
}
|