[TASK-2026-01-20-005] feat: Add multi-tenancy to UOM entities
EPIC-P2-005: UOM Multi-tenancy Sync - Add tenant_id field to Uom entity - Add tenant_id field to UomCategory entity - Add Tenant relation to both entities - Add UpdateDateColumn for updated_at - Update indexes for tenant-based unique constraints Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
24b6ba9b38
commit
8d201c5b58
@ -3,28 +3,43 @@ import {
|
|||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
Column,
|
Column,
|
||||||
CreateDateColumn,
|
CreateDateColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
Index,
|
Index,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
|
ManyToOne,
|
||||||
|
JoinColumn,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { Uom } from './uom.entity.js';
|
import { Uom } from './uom.entity.js';
|
||||||
|
import { Tenant } from '../../auth/entities/tenant.entity.js';
|
||||||
|
|
||||||
@Entity({ schema: 'core', name: 'uom_categories' })
|
@Entity({ schema: 'core', name: 'uom_categories' })
|
||||||
@Index('idx_uom_categories_name', ['name'], { unique: true })
|
@Index('idx_uom_categories_tenant', ['tenantId'])
|
||||||
|
@Index('idx_uom_categories_tenant_name', ['tenantId', 'name'], { unique: true })
|
||||||
export class UomCategory {
|
export class UomCategory {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column({ type: 'varchar', length: 100, nullable: false, unique: true })
|
@Column({ type: 'uuid', nullable: false, name: 'tenant_id' })
|
||||||
|
tenantId: string;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 100, nullable: false })
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column({ type: 'text', nullable: true })
|
@Column({ type: 'text', nullable: true })
|
||||||
description: string | null;
|
description: string | null;
|
||||||
|
|
||||||
// Relations
|
// Relations
|
||||||
|
@ManyToOne(() => Tenant)
|
||||||
|
@JoinColumn({ name: 'tenant_id' })
|
||||||
|
tenant: Tenant;
|
||||||
|
|
||||||
@OneToMany(() => Uom, (uom) => uom.category)
|
@OneToMany(() => Uom, (uom) => uom.category)
|
||||||
uoms: Uom[];
|
uoms: Uom[];
|
||||||
|
|
||||||
// Audit fields
|
// Audit fields
|
||||||
@CreateDateColumn({ name: 'created_at', type: 'timestamp' })
|
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
||||||
|
updatedAt: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,11 +3,13 @@ import {
|
|||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
Column,
|
Column,
|
||||||
CreateDateColumn,
|
CreateDateColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
Index,
|
Index,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
JoinColumn,
|
JoinColumn,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { UomCategory } from './uom-category.entity.js';
|
import { UomCategory } from './uom-category.entity.js';
|
||||||
|
import { Tenant } from '../../auth/entities/tenant.entity.js';
|
||||||
|
|
||||||
export enum UomType {
|
export enum UomType {
|
||||||
REFERENCE = 'reference',
|
REFERENCE = 'reference',
|
||||||
@ -16,14 +18,18 @@ export enum UomType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity({ schema: 'core', name: 'uom' })
|
@Entity({ schema: 'core', name: 'uom' })
|
||||||
|
@Index('idx_uom_tenant', ['tenantId'])
|
||||||
@Index('idx_uom_category_id', ['categoryId'])
|
@Index('idx_uom_category_id', ['categoryId'])
|
||||||
@Index('idx_uom_code', ['code'])
|
@Index('idx_uom_code', ['code'])
|
||||||
@Index('idx_uom_active', ['active'])
|
@Index('idx_uom_active', ['active'])
|
||||||
@Index('idx_uom_name_category', ['categoryId', 'name'], { unique: true })
|
@Index('idx_uom_tenant_category_name', ['tenantId', 'categoryId', 'name'], { unique: true })
|
||||||
export class Uom {
|
export class Uom {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
|
@Column({ type: 'uuid', nullable: false, name: 'tenant_id' })
|
||||||
|
tenantId: string;
|
||||||
|
|
||||||
@Column({ type: 'uuid', nullable: false, name: 'category_id' })
|
@Column({ type: 'uuid', nullable: false, name: 'category_id' })
|
||||||
categoryId: string;
|
categoryId: string;
|
||||||
|
|
||||||
@ -64,6 +70,10 @@ export class Uom {
|
|||||||
active: boolean;
|
active: boolean;
|
||||||
|
|
||||||
// Relations
|
// Relations
|
||||||
|
@ManyToOne(() => Tenant)
|
||||||
|
@JoinColumn({ name: 'tenant_id' })
|
||||||
|
tenant: Tenant;
|
||||||
|
|
||||||
@ManyToOne(() => UomCategory, (category) => category.uoms, {
|
@ManyToOne(() => UomCategory, (category) => category.uoms, {
|
||||||
nullable: false,
|
nullable: false,
|
||||||
})
|
})
|
||||||
@ -71,6 +81,9 @@ export class Uom {
|
|||||||
category: UomCategory;
|
category: UomCategory;
|
||||||
|
|
||||||
// Audit fields
|
// Audit fields
|
||||||
@CreateDateColumn({ name: 'created_at', type: 'timestamp' })
|
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
||||||
|
updatedAt: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user