ensure in uniqueness in tag

This commit is contained in:
hannathkadher
2024-12-11 10:37:21 +04:00
parent dc00fdc554
commit b945740fb8

View File

@ -1,10 +1,11 @@
import { Entity, Column, ManyToOne } from 'typeorm'; import { Entity, Column, ManyToOne, Unique } from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { SpaceEntity } from '../../space/entities';
import { SpaceProductItemDto } from '../dtos'; import { SpaceProductItemDto } from '../dtos';
import { SpaceProductModelEntity } from './space-product-model.entity'; import { SpaceProductModelEntity } from './space-product-model.entity';
import { SpaceModelEntity } from './space-model.entity';
@Entity({ name: 'space-product-item' }) @Entity({ name: 'space-product-item' })
@Unique(['tag', 'spaceProductModel', 'spaceModel'])
export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItemDto> { export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItemDto> {
@Column({ @Column({
nullable: false, nullable: false,
@ -16,14 +17,16 @@ export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItem
(spaceProductModel) => spaceProductModel.items, (spaceProductModel) => spaceProductModel.items,
{ {
nullable: false, nullable: false,
onDelete: 'CASCADE',
}, },
) )
public spaceProductModel: SpaceProductModelEntity; public spaceProductModel: SpaceProductModelEntity;
@ManyToOne(() => SpaceEntity, (space) => space.spaceProducts, { @ManyToOne(
nullable: true, () => SpaceModelEntity,
onDelete: 'CASCADE', (spaceModel) => spaceModel.spaceProductModels,
}) {
public space: SpaceEntity; // Optional for associating the item to a space directly nullable: false,
},
)
public spaceModel: SpaceModelEntity;
} }