mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 09:57:28 +00:00
Added space model, subspace model, space product model entities
This commit is contained in:
@ -28,6 +28,12 @@ import { SceneEntity, SceneIconEntity } from '../modules/scene/entities';
|
||||
import { SceneDeviceEntity } from '../modules/scene-device/entities';
|
||||
import { SpaceProductEntity } from '../modules/space/entities/space-product.entity';
|
||||
import { ProjectEntity } from '../modules/project/entities';
|
||||
import {
|
||||
SpaceModelEntity,
|
||||
SpaceProductItemModelEntity,
|
||||
SpaceProductModelEntity,
|
||||
SubspaceModelEntity,
|
||||
} from '../modules/space-model/entities';
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forRootAsync({
|
||||
@ -68,6 +74,10 @@ import { ProjectEntity } from '../modules/project/entities';
|
||||
SceneEntity,
|
||||
SceneIconEntity,
|
||||
SceneDeviceEntity,
|
||||
SpaceModelEntity,
|
||||
SpaceProductModelEntity,
|
||||
SpaceProductItemModelEntity,
|
||||
SubspaceModelEntity,
|
||||
],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||
|
@ -3,6 +3,7 @@ import { ProductDto } from '../dtos';
|
||||
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';
|
||||
|
||||
@Entity({ name: 'product' })
|
||||
export class ProductEntity extends AbstractEntity<ProductDto> {
|
||||
@ -30,6 +31,12 @@ export class ProductEntity extends AbstractEntity<ProductDto> {
|
||||
@OneToMany(() => SpaceProductEntity, (spaceProduct) => spaceProduct.product)
|
||||
spaceProducts: SpaceProductEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => SpaceProductModelEntity,
|
||||
(spaceProductModel) => spaceProductModel.product,
|
||||
)
|
||||
spaceProductModels: SpaceProductModelEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => DeviceEntity,
|
||||
(devicesProductEntity) => devicesProductEntity.productDevice,
|
||||
|
4
libs/common/src/modules/space-model/dtos/index.ts
Normal file
4
libs/common/src/modules/space-model/dtos/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './subspace-model.dto';
|
||||
export * from './space-model.dto';
|
||||
export * from './space-product-item.dto';
|
||||
export * from './space-product-model.dto';
|
15
libs/common/src/modules/space-model/dtos/space-model.dto.ts
Normal file
15
libs/common/src/modules/space-model/dtos/space-model.dto.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { IsString, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class SpaceModelDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public spaceModelName: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
projectUuid: string;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import { IsString, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class SpaceProductItemDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
tag: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
spaceProductModelUuid: string;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsNumber, IsString } 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[];
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import { IsString, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class SubSpaceModelDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public subSpaceModelName: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
spaceModelUuid: string;
|
||||
}
|
4
libs/common/src/modules/space-model/entities/index.ts
Normal file
4
libs/common/src/modules/space-model/entities/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './space-model.entity';
|
||||
export * from './space-product-item.entity';
|
||||
export * from './space-product-model.entity';
|
||||
export * from './subspace-model.entity';
|
@ -0,0 +1,38 @@
|
||||
import { Entity, Column, OneToMany } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceModelDto } from '../dtos';
|
||||
import { SubspaceModelEntity } from './subspace-model.entity';
|
||||
import { SpaceProductModelEntity } from './space-product-model.entity';
|
||||
|
||||
@Entity({ name: 'space-model' })
|
||||
export class SpaceModelEntity extends AbstractEntity<SpaceModelDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public modelName: string;
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceModelEntity,
|
||||
(subspaceModel) => subspaceModel.spaceModel,
|
||||
{
|
||||
cascade: true,
|
||||
},
|
||||
)
|
||||
public subspaceModels: SubspaceModelEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => SpaceProductModelEntity,
|
||||
(productModel) => productModel.spaceModel,
|
||||
{
|
||||
cascade: true,
|
||||
},
|
||||
)
|
||||
public spaceProductModels: SpaceProductModelEntity[];
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
import { Entity, Column, ManyToOne } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { SpaceProductItemDto } from '../dtos';
|
||||
import { SpaceProductModelEntity } from './space-product-model.entity';
|
||||
|
||||
@Entity({ name: 'space-product-item' })
|
||||
export class SpaceProductItemModelEntity extends AbstractEntity<SpaceProductItemDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public itemName: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => SpaceProductModelEntity,
|
||||
(spaceProductModel) => spaceProductModel.items,
|
||||
{
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
)
|
||||
public spaceProductModel: SpaceProductModelEntity;
|
||||
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.spaceProducts, {
|
||||
nullable: true,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
public space: SpaceEntity; // Optional for associating the item to a space directly
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
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.entity';
|
||||
import { SpaceProductModelDto } from '../dtos';
|
||||
|
||||
@Entity({ name: 'space-product-model' })
|
||||
export class SpaceProductModelEntity extends AbstractEntity<SpaceProductModelDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
type: 'int',
|
||||
})
|
||||
productCount: number;
|
||||
|
||||
@ManyToOne(
|
||||
() => SpaceModelEntity,
|
||||
(spaceModel) => spaceModel.spaceProductModels,
|
||||
{
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
)
|
||||
public spaceModel: SpaceModelEntity;
|
||||
|
||||
@ManyToOne(() => ProductEntity, (product) => product.spaceProductModels, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
public product: ProductEntity;
|
||||
|
||||
@OneToMany(
|
||||
() => SpaceProductItemModelEntity,
|
||||
(item) => item.spaceProductModel,
|
||||
{
|
||||
cascade: true,
|
||||
},
|
||||
)
|
||||
public items: SpaceProductItemModelEntity[];
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceModelEntity } from './space-model.entity';
|
||||
import { SubSpaceModelDto } from '../dtos';
|
||||
|
||||
@Entity({ name: 'subspace-model' })
|
||||
export class SubspaceModelEntity extends AbstractEntity<SubSpaceModelDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public subspaceName: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => SpaceModelEntity,
|
||||
(spaceModel) => spaceModel.subspaceModels,
|
||||
{
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
)
|
||||
public spaceModel: SpaceModelEntity;
|
||||
}
|
3
libs/common/src/modules/space-model/index.ts
Normal file
3
libs/common/src/modules/space-model/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './space-model.repository.module';
|
||||
export * from './entities';
|
||||
export * from './repositories';
|
@ -0,0 +1 @@
|
||||
export * from './space-model.repository';
|
@ -0,0 +1,34 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
SpaceModelEntity,
|
||||
SpaceProductItemModelEntity,
|
||||
SpaceProductModelEntity,
|
||||
SubspaceModelEntity,
|
||||
} from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceModelRepository extends Repository<SpaceModelEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SpaceModelEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
export class SubspaceModelRepository extends Repository<SubspaceModelEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SubspaceModelEntity, 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());
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import {
|
||||
SpaceModelEntity,
|
||||
SpaceProductItemModelEntity,
|
||||
SpaceProductModelEntity,
|
||||
SubspaceModelEntity,
|
||||
} from './entities';
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
SpaceModelEntity,
|
||||
SubspaceModelEntity,
|
||||
SpaceProductModelEntity,
|
||||
SpaceProductItemModelEntity,
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class SpaceModelRepositoryModule {}
|
Reference in New Issue
Block a user