diff --git a/projects/erp-suite/apps/verticales/construccion/backend/src/modules/construction/entities/fraccionamiento.entity.ts b/projects/erp-suite/apps/verticales/construccion/backend/src/modules/construction/entities/fraccionamiento.entity.ts new file mode 100644 index 0000000..1b7c510 --- /dev/null +++ b/projects/erp-suite/apps/verticales/construccion/backend/src/modules/construction/entities/fraccionamiento.entity.ts @@ -0,0 +1,90 @@ +/** + * Fraccionamiento Entity + * Obras/fraccionamientos dentro de un proyecto + * + * @module Construction + * @table construction.fraccionamientos + * @ddl schemas/01-construction-schema-ddl.sql + */ + +import { + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + UpdateDateColumn, + ManyToOne, + JoinColumn, + Index, +} from 'typeorm'; +import { Tenant } from '../../core/entities/tenant.entity'; +import { User } from '../../core/entities/user.entity'; +import { Proyecto } from './proyecto.entity'; + +export type EstadoFraccionamiento = 'activo' | 'pausado' | 'completado' | 'cancelado'; + +@Entity({ schema: 'construction', name: 'fraccionamientos' }) +@Index(['tenantId', 'codigo'], { unique: true }) +export class Fraccionamiento { + @PrimaryGeneratedColumn('uuid') + id: string; + + @Column({ name: 'tenant_id', type: 'uuid' }) + tenantId: string; + + @Column({ name: 'proyecto_id', type: 'uuid' }) + proyectoId: string; + + @Column({ type: 'varchar', length: 20 }) + codigo: string; + + @Column({ type: 'varchar', length: 200 }) + nombre: string; + + @Column({ type: 'text', nullable: true }) + descripcion: string; + + @Column({ type: 'text', nullable: true }) + direccion: string; + + // PostGIS geometry - stored as GeoJSON for TypeORM compatibility + @Column({ + name: 'ubicacion_geo', + type: 'geometry', + spatialFeatureType: 'Point', + srid: 4326, + nullable: true + }) + ubicacionGeo: string; + + @Column({ name: 'fecha_inicio', type: 'date', nullable: true }) + fechaInicio: Date; + + @Column({ name: 'fecha_fin_estimada', type: 'date', nullable: true }) + fechaFinEstimada: Date; + + @Column({ type: 'varchar', length: 20, default: 'activo' }) + estado: EstadoFraccionamiento; + + @CreateDateColumn({ name: 'created_at', type: 'timestamptz' }) + createdAt: Date; + + @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' }) + updatedAt: Date; + + @Column({ name: 'created_by', type: 'uuid', nullable: true }) + createdById: string; + + // Relations + @ManyToOne(() => Tenant) + @JoinColumn({ name: 'tenant_id' }) + tenant: Tenant; + + @ManyToOne(() => Proyecto, (p) => p.fraccionamientos) + @JoinColumn({ name: 'proyecto_id' }) + proyecto: Proyecto; + + @ManyToOne(() => User) + @JoinColumn({ name: 'created_by' }) + createdBy: User; +} diff --git a/projects/erp-suite/apps/verticales/construccion/backend/src/modules/construction/entities/index.ts b/projects/erp-suite/apps/verticales/construccion/backend/src/modules/construction/entities/index.ts new file mode 100644 index 0000000..bf60098 --- /dev/null +++ b/projects/erp-suite/apps/verticales/construccion/backend/src/modules/construction/entities/index.ts @@ -0,0 +1,7 @@ +/** + * Construction Entities Index + * @module Construction + */ + +export * from './proyecto.entity'; +export * from './fraccionamiento.entity'; diff --git a/projects/erp-suite/apps/verticales/construccion/backend/src/modules/construction/entities/proyecto.entity.ts b/projects/erp-suite/apps/verticales/construccion/backend/src/modules/construction/entities/proyecto.entity.ts new file mode 100644 index 0000000..95964d4 --- /dev/null +++ b/projects/erp-suite/apps/verticales/construccion/backend/src/modules/construction/entities/proyecto.entity.ts @@ -0,0 +1,88 @@ +/** + * Proyecto Entity + * Proyectos de desarrollo inmobiliario + * + * @module Construction + * @table construction.proyectos + * @ddl schemas/01-construction-schema-ddl.sql + */ + +import { + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + UpdateDateColumn, + ManyToOne, + OneToMany, + JoinColumn, + Index, +} from 'typeorm'; +import { Tenant } from '../../core/entities/tenant.entity'; +import { User } from '../../core/entities/user.entity'; +import { Fraccionamiento } from './fraccionamiento.entity'; + +export type EstadoProyecto = 'activo' | 'pausado' | 'completado' | 'cancelado'; + +@Entity({ schema: 'construction', name: 'proyectos' }) +@Index(['tenantId', 'codigo'], { unique: true }) +export class Proyecto { + @PrimaryGeneratedColumn('uuid') + id: string; + + @Column({ name: 'tenant_id', type: 'uuid' }) + tenantId: string; + + @Column({ type: 'varchar', length: 20 }) + codigo: string; + + @Column({ type: 'varchar', length: 200 }) + nombre: string; + + @Column({ type: 'text', nullable: true }) + descripcion: string; + + @Column({ type: 'text', nullable: true }) + direccion: string; + + @Column({ type: 'varchar', length: 100, nullable: true }) + ciudad: string; + + @Column({ type: 'varchar', length: 100, nullable: true }) + estado: string; + + @Column({ name: 'fecha_inicio', type: 'date', nullable: true }) + fechaInicio: Date; + + @Column({ name: 'fecha_fin_estimada', type: 'date', nullable: true }) + fechaFinEstimada: Date; + + @Column({ + name: 'estado_proyecto', + type: 'varchar', + length: 20, + default: 'activo' + }) + estadoProyecto: EstadoProyecto; + + @CreateDateColumn({ name: 'created_at', type: 'timestamptz' }) + createdAt: Date; + + @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' }) + updatedAt: Date; + + @Column({ name: 'created_by', type: 'uuid', nullable: true }) + createdById: string; + + // Relations + @ManyToOne(() => Tenant) + @JoinColumn({ name: 'tenant_id' }) + tenant: Tenant; + + @ManyToOne(() => User) + @JoinColumn({ name: 'created_by' }) + createdBy: User; + + @OneToMany(() => Fraccionamiento, (f) => f.proyecto) + fraccionamientos: Fraccionamiento[]; +}