clean model entities

This commit is contained in:
hannathkadher
2024-12-23 08:32:02 +04:00
parent 1df462712b
commit 2dd48b7bc2
25 changed files with 70 additions and 366 deletions
@@ -1,4 +1,2 @@
export * from './subspace-model';
export * from './space-model.dto';
export * from './space-product-item-model.dto';
export * from './space-product-model.dto';
@@ -1,15 +0,0 @@
import { IsString, IsNotEmpty } from 'class-validator';
export class SpaceProductItemModelDto {
@IsString()
@IsNotEmpty()
uuid: string;
@IsString()
@IsNotEmpty()
tag: string;
@IsString()
@IsNotEmpty()
spaceProductModelUuid: string;
}
@@ -1,19 +0,0 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
import { SpaceProductItemModelDto } from './space-product-item-model.dto';
export class SpaceProductModelDto {
@IsString()
@IsNotEmpty()
uuid: string;
@IsString()
@IsNotEmpty()
productUuid: string;
@ApiProperty({
description: 'List of individual items with specific names for the product',
type: [SpaceProductItemModelDto],
})
items: SpaceProductItemModelDto[];
}
@@ -1,3 +1 @@
export * from './subspace-model.dto';
export * from './subspace-product-item-model.dto';
export * from './subspace-product-model.dto';
@@ -1,15 +0,0 @@
import { IsString, IsNotEmpty } from 'class-validator';
export class SubspaceProductItemModelDto {
@IsString()
@IsNotEmpty()
uuid: string;
@IsString()
@IsNotEmpty()
tag: string;
@IsString()
@IsNotEmpty()
subspaceProductModelUuid: string;
}
@@ -1,19 +0,0 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
import { SubspaceProductItemModelDto } from './subspace-product-item-model.dto';
export class SubpaceProductModelDto {
@IsString()
@IsNotEmpty()
uuid: string;
@IsString()
@IsNotEmpty()
productUuid: string;
@ApiProperty({
description: 'List of individual items with specific names for the product',
type: [SubspaceProductItemModelDto],
})
items: SubspaceProductItemModelDto[];
}
@@ -0,0 +1,21 @@
import { IsNotEmpty, IsString } from 'class-validator';
export class TagModelDto {
@IsString()
@IsNotEmpty()
public uuid: string;
@IsString()
@IsNotEmpty()
public name: string;
@IsString()
@IsNotEmpty()
public productUuid: string;
@IsString()
spaceModelUuid: string;
@IsString()
subspaceModelUuid: string;
}
@@ -1,4 +1,3 @@
export * from './space-model.entity';
export * from './space-product-item-model.entity';
export * from './space-product-model.entity';
export * from './subspace-model';
export * from './tag-model.entity';
@@ -9,9 +9,9 @@ import {
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { SpaceModelDto } from '../dtos';
import { SubspaceModelEntity } from './subspace-model';
import { SpaceProductModelEntity } from './space-product-model.entity';
import { ProjectEntity } from '../../project/entities';
import { SpaceEntity } from '../../space/entities';
import { TagModel } from './tag-model.entity';
@Entity({ name: 'space-model' })
@Unique(['modelName', 'project'])
@@ -51,17 +51,11 @@ export class SpaceModelEntity extends AbstractEntity<SpaceModelDto> {
)
public subspaceModels: SubspaceModelEntity[];
@OneToMany(
() => SpaceProductModelEntity,
(productModel) => productModel.spaceModel,
{
nullable: true,
},
)
public spaceProductModels: SpaceProductModelEntity[];
@OneToMany(() => SpaceEntity, (space) => space.spaceModel, {
cascade: true,
})
public spaces: SpaceEntity[];
@OneToMany(() => TagModel, (tag) => tag.spaceModel)
tags: TagModel[];
}
@@ -1,35 +0,0 @@
import { Entity, Column, ManyToOne, OneToMany } from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { SpaceProductItemModelDto } from '../dtos';
import { SpaceProductModelEntity } from './space-product-model.entity';
import { SpaceProductItemEntity } from '../../space/entities';
@Entity({ name: 'space-product-item-model' })
export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItemModelDto> {
@Column({
nullable: false,
})
public tag: string;
@ManyToOne(
() => SpaceProductModelEntity,
(spaceProductModel) => spaceProductModel.items,
{
nullable: false,
},
)
public spaceProductModel: SpaceProductModelEntity;
@Column({
nullable: false,
default: false,
})
public disabled: boolean;
@OneToMany(
() => SpaceProductItemEntity,
(spaceProductItem) => spaceProductItem.spaceProductItemModel,
{ cascade: true },
)
public items: SpaceProductItemEntity[];
}
@@ -1,50 +0,0 @@
import { Entity, Column, ManyToOne, OneToMany } from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { ProductEntity } from '../../product/entities';
import { SpaceModelEntity } from './space-model.entity';
import { SpaceProductItemModelEntity } from './space-product-item-model.entity';
import { SpaceProductModelDto } from '../dtos';
import { SpaceProductEntity } from '../../space/entities';
@Entity({ name: 'space-product-model' })
export class SpaceProductModelEntity extends AbstractEntity<SpaceProductModelDto> {
@ManyToOne(
() => SpaceModelEntity,
(spaceModel) => spaceModel.spaceProductModels,
{
nullable: false,
onDelete: 'CASCADE',
},
)
public spaceModel: SpaceModelEntity;
@ManyToOne(() => ProductEntity, (product) => product.spaceProductModels, {
nullable: false,
onDelete: 'CASCADE',
})
public product: ProductEntity;
@Column({
nullable: false,
default: false,
})
public disabled: boolean;
@OneToMany(
() => SpaceProductItemModelEntity,
(item) => item.spaceProductModel,
{
cascade: true,
},
)
public items: SpaceProductItemModelEntity[];
@OneToMany(
() => SpaceProductEntity,
(spaceProduct) => spaceProduct.spaceProductModel,
{
cascade: true,
},
)
public spaceProducts: SpaceProductEntity[];
}
@@ -1,3 +1,2 @@
export * from './subspace-model.entity';
export * from './subspace-product-item-model.entity';
export * from './subspace-product-model.entity';
@@ -3,7 +3,7 @@ import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
import { SubSpaceModelDto } from '../../dtos';
import { SpaceModelEntity } from '../space-model.entity';
import { SubspaceEntity } from '@app/common/modules/space/entities';
import { SubspaceProductModelEntity } from './subspace-product-model.entity';
import { TagModel } from '../tag-model.entity';
@Entity({ name: 'subspace-model' })
@Unique(['subspaceName', 'spaceModel'])
@@ -41,12 +41,6 @@ export class SubspaceModelEntity extends AbstractEntity<SubSpaceModelDto> {
})
public disabled: boolean;
@OneToMany(
() => SubspaceProductModelEntity,
(productModel) => productModel.subspaceModel,
{
nullable: true,
},
)
public productModels: SubspaceProductModelEntity[];
@OneToMany(() => TagModel, (tag) => tag.subspaceModel)
tags: TagModel[];
}
@@ -1,33 +0,0 @@
import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
import { Entity, Column, ManyToOne, OneToMany } from 'typeorm';
import { SubspaceProductItemModelDto } from '../../dtos';
import { SubspaceProductModelEntity } from './subspace-product-model.entity';
import { SubspaceProductItemEntity } from '@app/common/modules/space/entities';
@Entity({ name: 'subspace-product-item-model' })
export class SubspaceProductItemModelEntity extends AbstractEntity<SubspaceProductItemModelDto> {
@Column({
nullable: false,
})
public tag: string;
@Column({
nullable: false,
default: false,
})
public disabled: boolean;
@ManyToOne(
() => SubspaceProductModelEntity,
(productModel) => productModel.itemModels,
{
nullable: false,
},
)
public subspaceProductModel: SubspaceProductModelEntity;
@OneToMany(() => SubspaceProductItemEntity, (item) => item.subspaceProduct, {
nullable: true,
})
items: SubspaceProductItemEntity[];
}
@@ -1,44 +0,0 @@
import { Entity, Column, ManyToOne, OneToMany } from 'typeorm';
import { SubpaceProductModelDto } from '../../dtos';
import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
import { SubspaceModelEntity } from './subspace-model.entity';
import { ProductEntity } from '@app/common/modules/product/entities';
import { SubspaceProductEntity } from '@app/common/modules/space/entities';
import { SubspaceProductItemModelEntity } from './subspace-product-item-model.entity';
@Entity({ name: 'subspace-product-model' })
export class SubspaceProductModelEntity extends AbstractEntity<SubpaceProductModelDto> {
@Column({
nullable: false,
default: false,
})
public disabled: boolean;
@ManyToOne(
() => SubspaceModelEntity,
(spaceModel) => spaceModel.productModels,
{
nullable: false,
},
)
public subspaceModel: SubspaceModelEntity;
@ManyToOne(() => ProductEntity, (product) => product.subpaceProductModels, {
nullable: false,
})
public product: ProductEntity;
@OneToMany(() => SubspaceProductEntity, (product) => product.model, {
nullable: true,
})
public subspaceProducts: SubspaceProductEntity[];
@OneToMany(
() => SubspaceProductItemModelEntity,
(product) => product.subspaceProductModel,
{
nullable: true,
},
)
public itemModels: SubspaceProductItemModelEntity[];
}
@@ -0,0 +1,29 @@
import { Column, Entity, JoinColumn, ManyToOne, Unique } from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { TagModelDto } from '../dtos/tag-model.dto';
import { SpaceModelEntity } from './space-model.entity';
import { SubspaceModelEntity } from './subspace-model';
import { ProductEntity } from '../../product/entities';
@Entity({ name: 'tag_model' })
@Unique(['tag', 'product', 'spaceModel', 'subspaceModel'])
export class TagModel extends AbstractEntity<TagModelDto> {
@Column({ type: 'varchar', length: 255 })
tag: string;
@ManyToOne(() => ProductEntity, (product) => product.tagModels, {
nullable: false,
})
@JoinColumn({ name: 'product_id' })
product: ProductEntity;
@ManyToOne(() => SpaceModelEntity, (space) => space.tags, { nullable: true })
@JoinColumn({ name: 'space_id' })
spaceModel: SpaceModelEntity;
@ManyToOne(() => SubspaceModelEntity, (subspace) => subspace.tags, {
nullable: true,
})
@JoinColumn({ name: 'subspace_id' })
subspaceModel: SubspaceModelEntity;
}
@@ -1,13 +1,6 @@
import { DataSource, Repository } from 'typeorm';
import { Injectable } from '@nestjs/common';
import {
SpaceModelEntity,
SpaceProductItemModelEntity,
SpaceProductModelEntity,
SubspaceModelEntity,
SubspaceProductItemModelEntity,
SubspaceProductModelEntity,
} from '../entities';
import { SpaceModelEntity, SubspaceModelEntity, TagModel } from '../entities';
@Injectable()
export class SpaceModelRepository extends Repository<SpaceModelEntity> {
@@ -23,28 +16,8 @@ export class SubspaceModelRepository extends Repository<SubspaceModelEntity> {
}
@Injectable()
export class SubspaceProductModelRepository extends Repository<SubspaceProductModelEntity> {
export class TagModelRepository extends Repository<TagModel> {
constructor(private dataSource: DataSource) {
super(SubspaceProductModelEntity, dataSource.createEntityManager());
}
}
@Injectable()
export class SubspaceProductItemModelRepository extends Repository<SubspaceProductItemModelEntity> {
constructor(private dataSource: DataSource) {
super(SubspaceProductItemModelEntity, dataSource.createEntityManager());
}
}
@Injectable()
export class SpaceProductModelRepository extends Repository<SpaceProductModelEntity> {
constructor(private dataSource: DataSource) {
super(SpaceProductModelEntity, dataSource.createEntityManager());
}
}
@Injectable()
export class SpaceProductItemModelRepository extends Repository<SpaceProductItemModelEntity> {
constructor(private dataSource: DataSource) {
super(SpaceProductItemModelEntity, dataSource.createEntityManager());
super(TagModel, dataSource.createEntityManager());
}
}
@@ -1,10 +1,5 @@
import { TypeOrmModule } from '@nestjs/typeorm';
import {
SpaceModelEntity,
SpaceProductItemModelEntity,
SpaceProductModelEntity,
SubspaceModelEntity,
} from './entities';
import { SpaceModelEntity, SubspaceModelEntity, TagModel } from './entities';
import { Module } from '@nestjs/common';
@Module({
@@ -12,12 +7,7 @@ import { Module } from '@nestjs/common';
exports: [],
controllers: [],
imports: [
TypeOrmModule.forFeature([
SpaceModelEntity,
SubspaceModelEntity,
SpaceProductModelEntity,
SpaceProductItemModelEntity,
]),
TypeOrmModule.forFeature([SpaceModelEntity, SubspaceModelEntity, TagModel]),
],
})
export class SpaceModelRepositoryModule {}