mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 08:14:54 +00:00
Merge pull request #178 from SyncrowIOT/feat/edit-space-model
Feat/edit space model
This commit is contained in:
@ -6,10 +6,11 @@ import {
|
||||
Unique,
|
||||
Index,
|
||||
JoinColumn,
|
||||
OneToOne,
|
||||
} from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
||||
import { SpaceEntity, SubspaceEntity } from '../../space/entities';
|
||||
import { SpaceEntity, SubspaceEntity, TagEntity } from '../../space/entities';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
import { DeviceNotificationDto } from '../dtos';
|
||||
@ -74,6 +75,11 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
@OneToMany(() => SceneDeviceEntity, (sceneDevice) => sceneDevice.device, {})
|
||||
sceneDevices: SceneDeviceEntity[];
|
||||
|
||||
@OneToOne(() => TagEntity, (tag) => tag.device, {
|
||||
nullable: true,
|
||||
})
|
||||
tag: TagEntity;
|
||||
|
||||
constructor(partial: Partial<DeviceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
@ -102,6 +108,7 @@ export class DeviceNotificationEntity extends AbstractEntity<DeviceNotificationD
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
|
||||
constructor(partial: Partial<DeviceNotificationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
||||
@ -2,10 +2,8 @@ import { Column, Entity, OneToMany } from 'typeorm';
|
||||
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';
|
||||
import { SubspaceProductModelEntity } from '../../space-model/entities/subspace-model/subspace-product-model.entity';
|
||||
|
||||
import { TagModel } from '../../space-model';
|
||||
import { TagEntity } from '../../space/entities/tag.entity';
|
||||
@Entity({ name: 'product' })
|
||||
export class ProductEntity extends AbstractEntity<ProductDto> {
|
||||
@Column({
|
||||
@ -29,20 +27,11 @@ export class ProductEntity extends AbstractEntity<ProductDto> {
|
||||
})
|
||||
public prodType: string;
|
||||
|
||||
@OneToMany(() => SpaceProductEntity, (spaceProduct) => spaceProduct.product)
|
||||
spaceProducts: SpaceProductEntity[];
|
||||
@OneToMany(() => TagModel, (tag) => tag.product)
|
||||
tagModels: TagModel[];
|
||||
|
||||
@OneToMany(
|
||||
() => SpaceProductModelEntity,
|
||||
(spaceProductModel) => spaceProductModel.product,
|
||||
)
|
||||
spaceProductModels: SpaceProductModelEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceProductModelEntity,
|
||||
(subspaceProductModel) => subspaceProductModel.product,
|
||||
)
|
||||
subpaceProductModels: SubspaceProductModelEntity[];
|
||||
@OneToMany(() => TagEntity, (tag) => tag.product)
|
||||
tags: TagEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => DeviceEntity,
|
||||
|
||||
@ -44,6 +44,12 @@ export class SceneDeviceEntity extends AbstractEntity<SceneDeviceDto> {
|
||||
@JoinColumn({ name: 'scene_uuid' })
|
||||
scene: SceneEntity;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
constructor(partial: Partial<SceneDeviceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
||||
@ -59,6 +59,12 @@ export class SceneEntity extends AbstractEntity<SceneDto> {
|
||||
@JoinColumn({ name: 'space_uuid' })
|
||||
space: SpaceEntity;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
@ManyToOne(() => SceneIconEntity, (icon) => icon.scenesIconEntity, {
|
||||
nullable: false,
|
||||
})
|
||||
|
||||
@ -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,23 +0,0 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
import { SpaceProductItemModelDto } from './space-product-item-model.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: [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,23 +0,0 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
import { SubspaceProductItemModelDto } from './subspace-product-item-model.dto';
|
||||
|
||||
export class SubpaceProductModelDto {
|
||||
@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: [SubspaceProductItemModelDto],
|
||||
})
|
||||
items: SubspaceProductItemModelDto[];
|
||||
}
|
||||
21
libs/common/src/modules/space-model/dtos/tag-model.dto.ts
Normal file
21
libs/common/src/modules/space-model/dtos/tag-model.dto.ts
Normal file
@ -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'])
|
||||
@ -28,6 +28,12 @@ export class SpaceModelEntity extends AbstractEntity<SpaceModelDto> {
|
||||
})
|
||||
public modelName: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
@ManyToOne(() => ProjectEntity, (project) => project.spaceModels, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
@ -45,17 +51,16 @@ 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[];
|
||||
|
||||
constructor(partial: Partial<SpaceModelEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,29 +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;
|
||||
|
||||
@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> {
|
||||
@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[];
|
||||
|
||||
@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'])
|
||||
@ -30,17 +30,17 @@ export class SubspaceModelEntity extends AbstractEntity<SubSpaceModelDto> {
|
||||
)
|
||||
public spaceModel: SpaceModelEntity;
|
||||
|
||||
@OneToMany(() => SubspaceEntity, (space) => space.subSpaceModel, {
|
||||
@OneToMany(() => SubspaceEntity, (subspace) => subspace.subSpaceModel, {
|
||||
cascade: true,
|
||||
})
|
||||
public spaces: SubspaceEntity[];
|
||||
public subspaceModel: SubspaceEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceProductModelEntity,
|
||||
(productModel) => productModel.subspaceModel,
|
||||
{
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
public productModels: SubspaceProductModelEntity[];
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
@OneToMany(() => TagModel, (tag) => tag.subspaceModel)
|
||||
tags: TagModel[];
|
||||
}
|
||||
|
||||
@ -1,27 +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;
|
||||
|
||||
@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,
|
||||
type: 'int',
|
||||
})
|
||||
productCount: number;
|
||||
|
||||
@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,46 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
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';
|
||||
import { TagEntity } from '../../space/entities/tag.entity';
|
||||
|
||||
@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_model_id' })
|
||||
spaceModel: SpaceModelEntity;
|
||||
|
||||
@ManyToOne(() => SubspaceModelEntity, (subspace) => subspace.tags, {
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({ name: 'subspace_model_id' })
|
||||
subspaceModel: SubspaceModelEntity;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
@OneToMany(() => TagEntity, (tag) => tag.model)
|
||||
tags: TagEntity[];
|
||||
}
|
||||
@ -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 {}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
export * from './space.dto';
|
||||
export * from './subspace.dto';
|
||||
export * from './space-product-item.dto';
|
||||
export * from './space-product.dto';
|
||||
export * from './tag.dto';
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
import { IsString, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class SpaceProductItemDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
tag: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
spaceProductUuid: string;
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
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[];
|
||||
}
|
||||
21
libs/common/src/modules/space/dtos/tag.dto.ts
Normal file
21
libs/common/src/modules/space/dtos/tag.dto.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class TagDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public name: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public productUuid: string;
|
||||
|
||||
@IsString()
|
||||
spaceUuid: string;
|
||||
|
||||
@IsString()
|
||||
subspaceUuid: string;
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
export * from './space.entity';
|
||||
export * from './subspace';
|
||||
export * from './space-product.entity';
|
||||
export * from './space-product-item.entity';
|
||||
export * from './space-link.entity';
|
||||
export * from './tag.entity';
|
||||
|
||||
@ -13,6 +13,12 @@ export class SpaceLinkEntity extends AbstractEntity {
|
||||
@JoinColumn({ name: 'end_space_id' })
|
||||
public endSpace: SpaceEntity;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
enum: Object.values(Direction),
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||
import { SpaceProductEntity } from './space-product.entity';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceProductItemDto } from '../dtos';
|
||||
import { SpaceProductItemModelEntity } from '../../space-model';
|
||||
|
||||
@Entity({ name: 'space-product-item' })
|
||||
export class SpaceProductItemEntity extends AbstractEntity<SpaceProductItemDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public tag: string;
|
||||
|
||||
@ManyToOne(() => SpaceProductEntity, (spaceProduct) => spaceProduct.items, {
|
||||
nullable: false,
|
||||
})
|
||||
public spaceProduct: SpaceProductEntity;
|
||||
|
||||
@ManyToOne(
|
||||
() => SpaceProductItemModelEntity,
|
||||
(spaceProductItemModel) => spaceProductItemModel.items,
|
||||
{
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
public spaceProductItemModel?: SpaceProductItemModelEntity;
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
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';
|
||||
import { SpaceProductModelEntity } from '../../space-model';
|
||||
|
||||
@Entity({ name: 'space-product' })
|
||||
export class SpaceProductEntity extends AbstractEntity<SpaceProductEntity> {
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.spaceProducts, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'space_uuid' })
|
||||
space: SpaceEntity;
|
||||
|
||||
@ManyToOne(() => ProductEntity, (product) => product.spaceProducts, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'product_uuid' })
|
||||
product: ProductEntity;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'int',
|
||||
})
|
||||
productCount: number;
|
||||
|
||||
@OneToMany(() => SpaceProductItemEntity, (item) => item.spaceProduct, {
|
||||
cascade: true,
|
||||
})
|
||||
public items: SpaceProductItemEntity[];
|
||||
|
||||
@ManyToOne(
|
||||
() => SpaceProductModelEntity,
|
||||
(spaceProductModel) => spaceProductModel.spaceProducts,
|
||||
{
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
@JoinColumn({ name: 'space_product_model_uuid' })
|
||||
public spaceProductModel?: SpaceProductModelEntity;
|
||||
|
||||
constructor(partial: Partial<SpaceProductEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@ -13,10 +13,10 @@ import { DeviceEntity } from '../../device/entities';
|
||||
import { CommunityEntity } from '../../community/entities';
|
||||
import { SubspaceEntity } from './subspace';
|
||||
import { SpaceLinkEntity } from './space-link.entity';
|
||||
import { SpaceProductEntity } from './space-product.entity';
|
||||
import { SceneEntity } from '../../scene/entities';
|
||||
import { SpaceModelEntity } from '../../space-model';
|
||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||
import { TagEntity } from './tag.entity';
|
||||
|
||||
@Entity({ name: 'space' })
|
||||
@Unique(['invitationCode'])
|
||||
@ -60,6 +60,12 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
@OneToMany(() => UserSpaceEntity, (userSpace) => userSpace.space)
|
||||
userSpaces: UserSpaceEntity[];
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
@OneToMany(() => SubspaceEntity, (subspace) => subspace.space, {
|
||||
nullable: true,
|
||||
})
|
||||
@ -94,14 +100,12 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
})
|
||||
public icon: string;
|
||||
|
||||
@OneToMany(() => SpaceProductEntity, (spaceProduct) => spaceProduct.space)
|
||||
spaceProducts: SpaceProductEntity[];
|
||||
|
||||
@OneToMany(() => SceneEntity, (scene) => scene.space)
|
||||
scenes: SceneEntity[];
|
||||
|
||||
@ManyToOne(() => SpaceModelEntity, { nullable: true })
|
||||
@JoinColumn({ name: 'space_model_uuid' })
|
||||
@ManyToOne(() => SpaceModelEntity, (spaceModel) => spaceModel.spaces, {
|
||||
nullable: true,
|
||||
})
|
||||
spaceModel?: SpaceModelEntity;
|
||||
|
||||
@OneToMany(
|
||||
@ -109,6 +113,10 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
(inviteUserSpace) => inviteUserSpace.space,
|
||||
)
|
||||
invitedUsers: InviteUserSpaceEntity[];
|
||||
|
||||
@OneToMany(() => TagEntity, (tag) => tag.space)
|
||||
tags: TagEntity[];
|
||||
|
||||
constructor(partial: Partial<SpaceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
||||
@ -1,3 +1 @@
|
||||
export * from './subspace.entity';
|
||||
export * from './subspace-product.entity';
|
||||
export * from './subspace-product-item.entity';
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
|
||||
import { SpaceProductItemDto } from '../../dtos';
|
||||
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||
import { SubspaceProductEntity } from './subspace-product.entity';
|
||||
import { SubspaceProductItemModelEntity } from '@app/common/modules/space-model';
|
||||
|
||||
@Entity({ name: 'subspace-product-item' })
|
||||
export class SubspaceProductItemEntity extends AbstractEntity<SpaceProductItemDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public tag: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => SubspaceProductEntity,
|
||||
(subspaceProduct) => subspaceProduct.items,
|
||||
{
|
||||
nullable: false,
|
||||
},
|
||||
)
|
||||
public subspaceProduct: SubspaceProductEntity;
|
||||
|
||||
@ManyToOne(() => SubspaceProductItemModelEntity, (model) => model.items, {
|
||||
nullable: true,
|
||||
})
|
||||
model: SubspaceProductItemModelEntity;
|
||||
|
||||
constructor(partial: Partial<SubspaceProductItemEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
import { ProductEntity } from '@app/common/modules/product/entities';
|
||||
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { SubspaceEntity } from './subspace.entity';
|
||||
import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
|
||||
import { SubspaceProductItemEntity } from './subspace-product-item.entity';
|
||||
import { SubspaceProductModelEntity } from '@app/common/modules/space-model';
|
||||
import { SpaceProductModelDto } from '../../dtos';
|
||||
|
||||
@Entity({ name: 'subspace-product' })
|
||||
export class SubspaceProductEntity extends AbstractEntity<SpaceProductModelDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
type: 'int',
|
||||
})
|
||||
productCount: number;
|
||||
|
||||
@ManyToOne(() => SubspaceEntity, (subspace) => subspace.subspaceProducts, {
|
||||
nullable: false,
|
||||
})
|
||||
public subspace: SubspaceEntity;
|
||||
|
||||
@ManyToOne(() => ProductEntity, (product) => product.subpaceProductModels, {
|
||||
nullable: false,
|
||||
})
|
||||
public product: ProductEntity;
|
||||
|
||||
@OneToMany(() => SubspaceProductItemEntity, (item) => item.subspaceProduct, {
|
||||
nullable: true,
|
||||
})
|
||||
public items: SubspaceProductItemEntity[];
|
||||
|
||||
@ManyToOne(
|
||||
() => SubspaceProductModelEntity,
|
||||
(model) => model.subspaceProducts,
|
||||
{
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
model: SubspaceProductModelEntity;
|
||||
}
|
||||
@ -4,7 +4,7 @@ import { SubspaceModelEntity } from '@app/common/modules/space-model';
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { SubspaceDto } from '../../dtos';
|
||||
import { SpaceEntity } from '../space.entity';
|
||||
import { SubspaceProductEntity } from './subspace-product.entity';
|
||||
import { TagEntity } from '../tag.entity';
|
||||
|
||||
@Entity({ name: 'subspace' })
|
||||
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
||||
@ -22,28 +22,28 @@ export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
||||
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.subspaces, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'space_uuid' })
|
||||
space: SpaceEntity;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
@OneToMany(() => DeviceEntity, (device) => device.subspace, {
|
||||
nullable: true,
|
||||
})
|
||||
devices: DeviceEntity[];
|
||||
|
||||
@ManyToOne(() => SubspaceModelEntity, { nullable: true })
|
||||
@JoinColumn({ name: 'subspace_model_uuid' })
|
||||
@ManyToOne(() => SubspaceModelEntity, (subspace) => subspace.subspaceModel, {
|
||||
nullable: true,
|
||||
})
|
||||
subSpaceModel?: SubspaceModelEntity;
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceProductEntity,
|
||||
(subspaceProduct) => subspaceProduct.subspace,
|
||||
{
|
||||
nullable: true,
|
||||
},
|
||||
)
|
||||
public subspaceProducts: SubspaceProductEntity[];
|
||||
@OneToMany(() => TagEntity, (tag) => tag.subspace)
|
||||
tags: TagEntity[];
|
||||
|
||||
constructor(partial: Partial<SubspaceEntity>) {
|
||||
super();
|
||||
|
||||
52
libs/common/src/modules/space/entities/tag.entity.ts
Normal file
52
libs/common/src/modules/space/entities/tag.entity.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
Unique,
|
||||
OneToOne,
|
||||
} from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
import { TagDto } from '../dtos';
|
||||
import { TagModel } from '../../space-model/entities/tag-model.entity';
|
||||
import { SpaceEntity } from './space.entity';
|
||||
import { SubspaceEntity } from './subspace';
|
||||
import { DeviceEntity } from '../../device/entities';
|
||||
|
||||
@Entity({ name: 'tag' })
|
||||
@Unique(['tag', 'product', 'space', 'subspace'])
|
||||
export class TagEntity extends AbstractEntity<TagDto> {
|
||||
@Column({ type: 'varchar', length: 255 })
|
||||
tag: string;
|
||||
|
||||
@ManyToOne(() => TagModel, (model) => model.tags, {
|
||||
nullable: true,
|
||||
})
|
||||
model: TagModel;
|
||||
|
||||
@ManyToOne(() => ProductEntity, (product) => product.tags, {
|
||||
nullable: false,
|
||||
})
|
||||
product: ProductEntity;
|
||||
|
||||
@ManyToOne(() => SpaceEntity, (space) => space.tags, { nullable: true })
|
||||
space: SpaceEntity;
|
||||
|
||||
@ManyToOne(() => SubspaceEntity, (subspace) => subspace.tags, {
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({ name: 'subspace_id' })
|
||||
subspace: SubspaceEntity;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: false,
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
@OneToOne(() => DeviceEntity, (device) => device.tag, {
|
||||
nullable: true,
|
||||
})
|
||||
device: DeviceEntity;
|
||||
}
|
||||
@ -1,11 +1,6 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SpaceProductEntity } from '../entities/space-product.entity';
|
||||
import {
|
||||
SpaceEntity,
|
||||
SpaceLinkEntity,
|
||||
SpaceProductItemEntity,
|
||||
} from '../entities';
|
||||
import { SpaceEntity, SpaceLinkEntity, TagEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceRepository extends Repository<SpaceEntity> {
|
||||
@ -20,16 +15,10 @@ export class SpaceLinkRepository extends Repository<SpaceLinkEntity> {
|
||||
super(SpaceLinkEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
export class SpaceProductRepository extends Repository<SpaceProductEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SpaceProductEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SpaceProductItemRepository extends Repository<SpaceProductItemEntity> {
|
||||
export class TagRepository extends Repository<TagEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SpaceProductItemEntity, dataSource.createEntityManager());
|
||||
super(TagEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import {
|
||||
SubspaceEntity,
|
||||
SubspaceProductEntity,
|
||||
SubspaceProductItemEntity,
|
||||
} from '../entities';
|
||||
import { SubspaceEntity } from '../entities';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
@ -12,17 +8,3 @@ export class SubspaceRepository extends Repository<SubspaceEntity> {
|
||||
super(SubspaceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SubspaceProductRepository extends Repository<SubspaceProductEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SubspaceProductEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SubspaceProductItemRepository extends Repository<SubspaceProductItemEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(SubspaceProductItemEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SpaceEntity, SubspaceEntity, SubspaceProductEntity } from './entities';
|
||||
import { SpaceEntity, SubspaceEntity, TagEntity } from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
SpaceEntity,
|
||||
SubspaceEntity,
|
||||
SubspaceProductEntity,
|
||||
]),
|
||||
],
|
||||
imports: [TypeOrmModule.forFeature([SpaceEntity, SubspaceEntity, TagEntity])],
|
||||
})
|
||||
export class SpaceRepositoryModule {}
|
||||
|
||||
Reference in New Issue
Block a user