mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
added subspace model product and item entities
This commit is contained in:
@ -34,6 +34,8 @@ import {
|
||||
SpaceProductItemModelEntity,
|
||||
SpaceProductModelEntity,
|
||||
SubspaceModelEntity,
|
||||
SubspaceProductItemModelEntity,
|
||||
SubspaceProductModelEntity,
|
||||
} from '../modules/space-model/entities';
|
||||
@Module({
|
||||
imports: [
|
||||
@ -81,6 +83,8 @@ import {
|
||||
SubspaceModelEntity,
|
||||
SpaceProductEntity,
|
||||
SpaceProductItemEntity,
|
||||
SubspaceProductModelEntity,
|
||||
SubspaceProductItemModelEntity,
|
||||
],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||
|
@ -4,6 +4,7 @@ import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { DeviceEntity } from '../../device/entities';
|
||||
import { SpaceProductEntity } from '../../space/entities/space-product.entity';
|
||||
import { SpaceProductModelEntity } from '../../space-model/entities';
|
||||
import { SubspaceProductModelEntity } from '../../space-model/entities/subspace-model/subspace-product-model.entity';
|
||||
|
||||
@Entity({ name: 'product' })
|
||||
export class ProductEntity extends AbstractEntity<ProductDto> {
|
||||
@ -37,6 +38,12 @@ export class ProductEntity extends AbstractEntity<ProductDto> {
|
||||
)
|
||||
spaceProductModels: SpaceProductModelEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceProductModelEntity,
|
||||
(subspaceProductModel) => subspaceProductModel.product,
|
||||
)
|
||||
subpaceProductModels: SubspaceProductModelEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => DeviceEntity,
|
||||
(devicesProductEntity) => devicesProductEntity.productDevice,
|
||||
|
@ -49,7 +49,6 @@ export class SpaceModelEntity extends AbstractEntity<SpaceModelDto> {
|
||||
() => SpaceProductModelEntity,
|
||||
(productModel) => productModel.spaceModel,
|
||||
{
|
||||
cascade: true,
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
|
@ -1 +1,3 @@
|
||||
export * from './subspace-model.entity';
|
||||
export * from './subspace-product-item-model.entity';
|
||||
export * from './subspace-product-model.entity';
|
||||
|
@ -3,6 +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';
|
||||
|
||||
@Entity({ name: 'subspace-model' })
|
||||
@Unique(['subspaceName', 'spaceModel'])
|
||||
@ -33,4 +34,13 @@ export class SubspaceModelEntity extends AbstractEntity<SubSpaceModelDto> {
|
||||
cascade: true,
|
||||
})
|
||||
public spaces: SubspaceEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceProductModelEntity,
|
||||
(productModel) => productModel.subspaceModel,
|
||||
{
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
public subspaceProductModels: SubspaceProductModelEntity[];
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
|
||||
import { Entity, Column, ManyToOne } from 'typeorm';
|
||||
import { SubspaceProductItemModelDto } from '../../dtos';
|
||||
import { SubspaceProductModelEntity } from './subspace-product-model.entity';
|
||||
|
||||
@Entity({ name: 'subspace-product-item-model' })
|
||||
export class SubspaceProductItemModelEntity extends AbstractEntity<SubspaceProductItemModelDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public tag: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => SubspaceProductModelEntity,
|
||||
(subspaceProductModel) => subspaceProductModel.items,
|
||||
{
|
||||
nullable: false,
|
||||
},
|
||||
)
|
||||
public subspaceProductModel: SubspaceProductModelEntity;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
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 { SubspaceProductItemModelEntity } from './subspace-product-item-model.entity';
|
||||
|
||||
@Entity({ name: 'subspace-product-model' })
|
||||
export class SubspaceProductModelEntity extends AbstractEntity<SubpaceProductModelDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
type: 'int',
|
||||
})
|
||||
productCount: number;
|
||||
|
||||
@ManyToOne(
|
||||
() => SubspaceModelEntity,
|
||||
(spaceModel) => spaceModel.subspaceProductModels,
|
||||
{
|
||||
nullable: false,
|
||||
},
|
||||
)
|
||||
public subspaceModel: SubspaceModelEntity;
|
||||
|
||||
@ManyToOne(() => ProductEntity, (product) => product.subpaceProductModels, {
|
||||
nullable: false,
|
||||
})
|
||||
public product: ProductEntity;
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceProductItemModelEntity,
|
||||
(item) => item.subspaceProductModel,
|
||||
{
|
||||
cascade: true,
|
||||
},
|
||||
)
|
||||
public items: SubspaceProductItemModelEntity[];
|
||||
}
|
Reference in New Issue
Block a user