added entities for space product item

This commit is contained in:
hannathkadher
2024-12-11 15:27:06 +04:00
parent 37d016ea43
commit 88a4b26919
12 changed files with 80 additions and 24 deletions
@@ -1,2 +1,4 @@
export * from './space.dto';
export * from './subspace.dto';
export * from './space-product-item.dto';
export * from './space-product.dto';
@@ -0,0 +1,15 @@
import { IsString, IsNotEmpty } from 'class-validator';
export class SpaceProductItemDto {
@IsString()
@IsNotEmpty()
uuid: string;
@IsString()
@IsNotEmpty()
tag: string;
@IsString()
@IsNotEmpty()
spaceProductUuid: string;
}
@@ -0,0 +1,23 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty, IsNumber } from 'class-validator';
import { SpaceProductItemDto } from './space-product-item.dto';
export class SpaceProductModelDto {
@IsString()
@IsNotEmpty()
uuid: string;
@IsNumber()
@IsNotEmpty()
productCount: number;
@IsString()
@IsNotEmpty()
productUuid: string;
@ApiProperty({
description: 'List of individual items with specific names for the product',
type: [SpaceProductItemDto],
})
items: SpaceProductItemDto[];
}
@@ -1,3 +1,5 @@
export * from './space.entity';
export * from './subspace.entity';
export * from './space-product-item.entity';
export * from './space-product.entity';
export * from './space-link.entity';
@@ -0,0 +1,17 @@
import { Column, Entity, ManyToOne } from 'typeorm';
import { SpaceProductEntity } from './space-product.entity';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { SpaceProductItemDto } from '../dtos';
@Entity({ name: 'space-product-item-model' })
export class SpaceProductItemEntity extends AbstractEntity<SpaceProductItemDto> {
@Column({
nullable: false,
})
public tag: string;
@ManyToOne(() => SpaceProductEntity, (spaceProduct) => spaceProduct.items, {
nullable: false,
})
public spaceProducts: SpaceProductEntity;
}
@@ -1,7 +1,8 @@
import { Column, Entity, ManyToOne, JoinColumn } from 'typeorm';
import { Column, Entity, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
import { SpaceEntity } from './space.entity';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { ProductEntity } from '../../product/entities';
import { SpaceProductItemEntity } from './space-product-item.entity';
@Entity({ name: 'space-product' })
export class SpaceProductEntity extends AbstractEntity<SpaceProductEntity> {
@@ -25,6 +26,11 @@ export class SpaceProductEntity extends AbstractEntity<SpaceProductEntity> {
})
productCount: number;
@OneToMany(() => SpaceProductItemEntity, (item) => item.spaceProducts, {
cascade: true,
})
public items: SpaceProductItemEntity[];
constructor(partial: Partial<SpaceProductEntity>) {
super();
Object.assign(this, partial);