56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
/**
|
|
* Part Category Entity
|
|
* Mecánicas Diesel - ERP Suite
|
|
*
|
|
* Represents part categories with hierarchical structure.
|
|
*/
|
|
|
|
import {
|
|
Entity,
|
|
PrimaryGeneratedColumn,
|
|
Column,
|
|
CreateDateColumn,
|
|
UpdateDateColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
JoinColumn,
|
|
Index,
|
|
} from 'typeorm';
|
|
|
|
@Entity({ name: 'part_categories', schema: 'parts_management' })
|
|
@Index('idx_part_categories_tenant', ['tenantId'])
|
|
@Index('idx_part_categories_parent', ['parentId'])
|
|
export class PartCategory {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column({ name: 'tenant_id', type: 'uuid' })
|
|
tenantId: string;
|
|
|
|
@Column({ type: 'varchar', length: 100 })
|
|
name: string;
|
|
|
|
@Column({ type: 'varchar', length: 300, nullable: true })
|
|
description?: string;
|
|
|
|
@Column({ name: 'parent_id', type: 'uuid', nullable: true })
|
|
parentId?: string;
|
|
|
|
@Column({ name: 'sort_order', type: 'integer', default: 0 })
|
|
sortOrder: number;
|
|
|
|
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
|
createdAt: Date;
|
|
|
|
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
|
updatedAt: Date;
|
|
|
|
// Relations
|
|
@ManyToOne(() => PartCategory, category => category.children, { nullable: true })
|
|
@JoinColumn({ name: 'parent_id' })
|
|
parent?: PartCategory;
|
|
|
|
@OneToMany(() => PartCategory, category => category.parent)
|
|
children: PartCategory[];
|
|
}
|