erp-construccion-backend-v2/src/modules/auth/entities/role.entity.ts
Adrian Flores Cortes 598c3215e1 feat(FASE-4A): Complete vertical modules for construction
- MAI-018 Bidding module: entities, services, controllers, DTOs
  - Opportunity, Tender, Proposal, Vendor management
  - Bid calendar, documents, analytics
- Earned Value Management: Curva S, SPI/CPI reports
  - earned-value.service.ts with EV, PV, AC calculations
  - earned-value.controller.ts with 9 endpoints
- DTOs for modules: assets, contracts, documents, purchase, quality
  - 28 new DTO files with class-validator decorators
- Storage module: service and controller implementation
  - Multi-provider support (local, S3, GCS, Azure)
  - File management, upload/download URLs
- Multiple entity and service fixes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 07:00:18 -06:00

91 lines
2.3 KiB
TypeScript

/**
* Role Entity
* Roles del sistema para RBAC
* Compatible con erp-core role.entity
*
* @module Auth
*/
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
OneToMany,
ManyToMany,
ManyToOne,
JoinColumn,
JoinTable,
Index,
} from 'typeorm';
import { Permission } from './permission.entity';
import { UserRole } from './user-role.entity';
import { Tenant } from '../../core/entities/tenant.entity';
@Entity({ schema: 'auth', name: 'roles' })
@Index('idx_roles_tenant_id', ['tenantId'])
@Index('idx_roles_code', ['code'])
@Index('idx_roles_is_system', ['isSystem'])
export class Role {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'uuid', nullable: true, name: 'tenant_id' })
tenantId: string | null;
@Column({ type: 'varchar', length: 50, unique: true })
code: string;
@Column({ type: 'varchar', length: 100 })
name: string;
@Column({ type: 'text', nullable: true })
description: string | null;
@Column({ name: 'is_system', type: 'boolean', default: false })
isSystem: boolean;
@Column({ name: 'is_active', type: 'boolean', default: true })
isActive: boolean;
@Column({ type: 'varchar', length: 20, nullable: true })
color: string | null;
// Relations
@ManyToOne(() => Tenant, { onDelete: 'CASCADE', nullable: true })
@JoinColumn({ name: 'tenant_id' })
tenant: Tenant | null;
@ManyToMany(() => Permission)
@JoinTable({
name: 'role_permissions',
schema: 'auth',
joinColumn: { name: 'role_id', referencedColumnName: 'id' },
inverseJoinColumn: { name: 'permission_id', referencedColumnName: 'id' },
})
permissions: Permission[];
@OneToMany(() => UserRole, (userRole) => userRole.role)
userRoles: UserRole[];
// Audit trail
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
createdAt: Date;
@Column({ type: 'uuid', nullable: true, name: 'created_by' })
createdBy: string | null;
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
updatedAt: Date;
@Column({ type: 'uuid', nullable: true, name: 'updated_by' })
updatedBy: string | null;
@Column({ name: 'deleted_at', type: 'timestamptz', nullable: true })
deletedAt: Date | null;
@Column({ type: 'uuid', nullable: true, name: 'deleted_by' })
deletedBy: string | null;
}