mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-24 23:37:54 +00:00
fixed entity relation, removed circular dependency
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export * from './space.dto';
|
||||
export * from './subspace.dto';
|
||||
export * from './tag.dto';
|
||||
export * from './space-product-allocation.dto';
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { IsArray, IsNotEmpty, IsString, ValidateNested } from 'class-validator';
|
||||
import { SpaceDto } from './space.dto';
|
||||
import { Type } from 'class-transformer';
|
||||
import { ProductDto } from '../../product/dtos';
|
||||
import { NewTagDto } from '../../tag/dtos';
|
||||
|
||||
export class SpaceProductAllocationDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => SpaceDto)
|
||||
public space: SpaceDto;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => ProductDto)
|
||||
product: ProductDto;
|
||||
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => NewTagDto)
|
||||
allowedTags: NewTagDto[];
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { IsArray, IsNotEmpty, IsString, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { ProductDto } from '../../product/dtos';
|
||||
import { NewTagDto } from '../../tag/dtos';
|
||||
import { SubspaceDto } from './subspace.dto';
|
||||
|
||||
export class SubspaceProductAllocationDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => SubspaceDto)
|
||||
public subspace: SubspaceDto;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => ProductDto)
|
||||
product: ProductDto;
|
||||
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => NewTagDto)
|
||||
allowedTags: NewTagDto[];
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export * from './space.entity';
|
||||
export * from './subspace';
|
||||
export * from './space-link.entity';
|
||||
export * from './tag.entity';
|
||||
@@ -1,11 +1,13 @@
|
||||
import { Entity, Column, ManyToOne, ManyToMany, JoinTable } from 'typeorm';
|
||||
import { SpaceEntity } from './space.entity';
|
||||
import { SpaceModelProductAllocationEntity } from '../../space-model';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
import { NewTagEntity } from '../../tag';
|
||||
import { SpaceModelProductAllocationEntity } from '../../space-model/entities/space-model-product-allocation.entity';
|
||||
import { ProductEntity } from '../../product/entities/product.entity';
|
||||
import { NewTagEntity } from '../../tag/entities/tag.entity';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceProductAllocationDto } from '../dtos/space-product-allocation.dto';
|
||||
|
||||
@Entity({ name: 'space_product_allocation' })
|
||||
export class SpaceProductAllocationEntity {
|
||||
export class SpaceProductAllocationEntity extends AbstractEntity<SpaceProductAllocationDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
@@ -34,4 +36,9 @@ export class SpaceProductAllocationEntity {
|
||||
@ManyToMany(() => NewTagEntity)
|
||||
@JoinTable({ name: 'space_product_tags' })
|
||||
public allowedTags: NewTagEntity[];
|
||||
|
||||
constructor(partial: Partial<SpaceProductAllocationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { UserSpaceEntity } from '../../user/entities';
|
||||
import { DeviceEntity } from '../../device/entities';
|
||||
import { CommunityEntity } from '../../community/entities';
|
||||
import { SubspaceEntity } from './subspace';
|
||||
import { SpaceLinkEntity } from './space-link.entity';
|
||||
import { SceneEntity } from '../../scene/entities';
|
||||
import { SpaceModelEntity } from '../../space-model';
|
||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||
import { TagEntity } from './tag.entity';
|
||||
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
||||
import { SubspaceEntity } from './subspace/subspace.entity';
|
||||
|
||||
@Entity({ name: 'space' })
|
||||
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './subspace.entity';
|
||||
export * from './subspace-product-allocation.entity';
|
||||
+10
-3
@@ -8,12 +8,14 @@ import {
|
||||
} from 'typeorm';
|
||||
import { SubspaceEntity } from './subspace.entity';
|
||||
import { ProductEntity } from '@app/common/modules/product/entities';
|
||||
import { NewTagEntity } from '@app/common/modules/tag';
|
||||
import { SubspaceModelProductAllocationEntity } from '@app/common/modules/space-model';
|
||||
import { NewTagEntity } from '@app/common/modules/tag/entities/tag.entity';
|
||||
import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
|
||||
import { SubspaceProductAllocationDto } from '../../dtos/subspace-product-allocation.dto';
|
||||
|
||||
@Entity({ name: 'subspace_product_allocation' })
|
||||
@Unique(['subspaceModel', 'product', 'allowedTags'])
|
||||
export class SubspaceProductAllocationEntity {
|
||||
@Unique(['subspace', 'product'])
|
||||
export class SubspaceProductAllocationEntity extends AbstractEntity<SubspaceProductAllocationDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
@@ -42,4 +44,9 @@ export class SubspaceProductAllocationEntity {
|
||||
@ManyToMany(() => NewTagEntity)
|
||||
@JoinTable({ name: 'subspace_product_tags' })
|
||||
public allowedTags: NewTagEntity[];
|
||||
|
||||
constructor(partial: Partial<SubspaceProductAllocationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ 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';
|
||||
import { SubspaceEntity } from './subspace/subspace.entity';
|
||||
|
||||
@Entity({ name: 'tag' })
|
||||
export class TagEntity extends AbstractEntity<TagDto> {
|
||||
@Column({ type: 'varchar', length: 255 })
|
||||
@Column({ type: 'varchar', length: 255, nullable: true })
|
||||
tag: string;
|
||||
|
||||
@ManyToOne(() => TagModel, (model) => model.tags, {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from './dtos';
|
||||
export * from './entities';
|
||||
export * from './repositories';
|
||||
export * from './space.repository.module';
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SpaceEntity, SpaceLinkEntity, TagEntity } from '../entities';
|
||||
import { InviteSpaceEntity } from '../entities/invite-space.entity';
|
||||
import { SpaceLinkEntity } from '../entities/space-link.entity';
|
||||
import { SpaceEntity } from '../entities/space.entity';
|
||||
import { TagEntity } from '../entities/tag.entity';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceRepository extends Repository<SpaceEntity> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { SubspaceEntity } from '../entities';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SubspaceEntity } from '../entities/subspace/subspace.entity';
|
||||
|
||||
@Injectable()
|
||||
export class SubspaceRepository extends Repository<SubspaceEntity> {
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SpaceEntity, SubspaceEntity, TagEntity } from './entities';
|
||||
|
||||
import { InviteSpaceEntity } from './entities/invite-space.entity';
|
||||
import { SpaceProductAllocationEntity } from './entities/space-product-allocation.entity';
|
||||
import { SpaceEntity } from './entities/space.entity';
|
||||
import { SubspaceProductAllocationEntity } from './entities/subspace/subspace-product-allocation.entity';
|
||||
import { SubspaceEntity } from './entities/subspace/subspace.entity';
|
||||
import { TagEntity } from './entities/tag.entity';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
@@ -13,6 +18,8 @@ import { InviteSpaceEntity } from './entities/invite-space.entity';
|
||||
SubspaceEntity,
|
||||
TagEntity,
|
||||
InviteSpaceEntity,
|
||||
SpaceProductAllocationEntity,
|
||||
SubspaceProductAllocationEntity,
|
||||
]),
|
||||
],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user