[EPIC-002] feat: Add user_id to Employee + rename warehouse_type

T2.1: Renamed warehouse_type -> construction_warehouse_type
      to avoid conflict with ERP-Core warehouses.warehouse_type

T2.3: Added user_id FK to hr.employees for employee-user mapping
      - Nullable (employees can exist without system access)
      - Unique constraint (1:1 relationship)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Adrian Flores Cortes 2026-02-04 00:19:50 -06:00
parent 1ad1604fa9
commit 2fc091c656
2 changed files with 12 additions and 2 deletions

View File

@ -29,6 +29,7 @@ export type Genero = 'M' | 'F';
@Entity({ schema: 'hr', name: 'employees' }) @Entity({ schema: 'hr', name: 'employees' })
@Index(['tenantId', 'codigo'], { unique: true }) @Index(['tenantId', 'codigo'], { unique: true })
@Index(['tenantId', 'curp'], { unique: true }) @Index(['tenantId', 'curp'], { unique: true })
@Index(['userId'], { unique: true })
export class Employee { export class Employee {
@PrimaryGeneratedColumn('uuid') @PrimaryGeneratedColumn('uuid')
id: string; id: string;
@ -111,6 +112,10 @@ export class Employee {
@Column({ name: 'created_by', type: 'uuid', nullable: true }) @Column({ name: 'created_by', type: 'uuid', nullable: true })
createdById: string; createdById: string;
// Mapeo a usuario del sistema (opcional - empleado puede no tener acceso)
@Column({ name: 'user_id', type: 'uuid', nullable: true })
userId: string;
// Relations // Relations
@ManyToOne(() => Tenant) @ManyToOne(() => Tenant)
@JoinColumn({ name: 'tenant_id' }) @JoinColumn({ name: 'tenant_id' })
@ -124,6 +129,11 @@ export class Employee {
@JoinColumn({ name: 'created_by' }) @JoinColumn({ name: 'created_by' })
createdBy: User; createdBy: User;
// Relación a usuario del sistema (1:1, opcional)
@ManyToOne(() => User, { nullable: true })
@JoinColumn({ name: 'user_id' })
user: User;
@OneToMany(() => EmployeeFraccionamiento, (ef) => ef.employee) @OneToMany(() => EmployeeFraccionamiento, (ef) => ef.employee)
asignaciones: EmployeeFraccionamiento[]; asignaciones: EmployeeFraccionamiento[];

View File

@ -40,12 +40,12 @@ export class AlmacenProyecto {
fraccionamientoId: string; fraccionamientoId: string;
@Column({ @Column({
name: 'warehouse_type', name: 'construction_warehouse_type',
type: 'varchar', type: 'varchar',
length: 20, length: 20,
default: 'obra', default: 'obra',
}) })
warehouseType: WarehouseTypeConstruction; constructionWarehouseType: WarehouseTypeConstruction;
@Column({ name: 'location_description', type: 'text', nullable: true }) @Column({ name: 'location_description', type: 'text', nullable: true })
locationDescription: string; locationDescription: string;