mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
fixed entity relation, removed circular dependency
This commit is contained in:
@ -8,13 +8,7 @@ import { UserOtpEntity } from '../modules/user/entities';
|
||||
import { ProductEntity } from '../modules/product/entities';
|
||||
import { DeviceEntity } from '../modules/device/entities';
|
||||
import { PermissionTypeEntity } from '../modules/permission/entities';
|
||||
import {
|
||||
SpaceEntity,
|
||||
SpaceLinkEntity,
|
||||
SubspaceEntity,
|
||||
SubspaceProductAllocationEntity,
|
||||
TagEntity,
|
||||
} from '../modules/space/entities';
|
||||
|
||||
import { UserSpaceEntity } from '../modules/user/entities';
|
||||
import { DeviceUserPermissionEntity } from '../modules/device/entities';
|
||||
import { RoleTypeEntity } from '../modules/role-type/entities';
|
||||
@ -42,7 +36,12 @@ import {
|
||||
import { InviteSpaceEntity } from '../modules/space/entities/invite-space.entity';
|
||||
import { AutomationEntity } from '../modules/automation/entities';
|
||||
import { SpaceProductAllocationEntity } from '../modules/space/entities/space-product-allocation.entity';
|
||||
import { NewTagEntity } from '../modules/tag';
|
||||
import { NewTagEntity } from '../modules/tag/entities/tag.entity';
|
||||
import { SpaceEntity } from '../modules/space/entities/space.entity';
|
||||
import { SpaceLinkEntity } from '../modules/space/entities/space-link.entity';
|
||||
import { SubspaceProductAllocationEntity } from '../modules/space/entities/subspace/subspace-product-allocation.entity';
|
||||
import { SubspaceEntity } from '../modules/space/entities/subspace/subspace.entity';
|
||||
import { TagEntity } from '../modules/space/entities/tag.entity';
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forRootAsync({
|
||||
@ -57,6 +56,7 @@ import { NewTagEntity } from '../modules/tag';
|
||||
password: configService.get('DB_PASSWORD'),
|
||||
database: configService.get('DB_NAME'),
|
||||
entities: [
|
||||
NewTagEntity,
|
||||
ProjectEntity,
|
||||
UserEntity,
|
||||
UserSessionEntity,
|
||||
@ -93,7 +93,6 @@ import { NewTagEntity } from '../modules/tag';
|
||||
SubspaceModelProductAllocationEntity,
|
||||
SpaceProductAllocationEntity,
|
||||
SubspaceProductAllocationEntity,
|
||||
NewTagEntity,
|
||||
],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||
|
@ -12,10 +12,10 @@ import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { RoleTypeEntity } from '../../role-type/entities';
|
||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { InviteUserDto, InviteUserSpaceDto } from '../dtos';
|
||||
import { ProjectEntity } from '../../project/entities';
|
||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
|
||||
@Entity({ name: 'invite-user' })
|
||||
@Unique(['email', 'project'])
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
|
||||
import { AutomationDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
|
||||
@Entity({ name: 'automation' })
|
||||
export class AutomationEntity extends AbstractEntity<AutomationDto> {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { CommunityDto } from '../dtos';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { ProjectEntity } from '../../project/entities';
|
||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
|
||||
@Entity({ name: 'community' })
|
||||
@Unique(['name'])
|
||||
|
@ -7,15 +7,19 @@ import {
|
||||
Index,
|
||||
JoinColumn,
|
||||
OneToOne,
|
||||
JoinTable,
|
||||
} from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
||||
import { SpaceEntity, SubspaceEntity, TagEntity } from '../../space/entities';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
import { DeviceNotificationDto } from '../dtos';
|
||||
import { PermissionTypeEntity } from '../../permission/entities';
|
||||
import { SceneDeviceEntity } from '../../scene-device/entities';
|
||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
import { SubspaceEntity } from '../../space/entities/subspace/subspace.entity';
|
||||
import { TagEntity } from '../../space/entities/tag.entity';
|
||||
import { NewTagEntity } from '../../tag';
|
||||
|
||||
@Entity({ name: 'device' })
|
||||
@Unique(['deviceTuyaUuid'])
|
||||
@ -80,6 +84,10 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
})
|
||||
tag: TagEntity;
|
||||
|
||||
@OneToMany(() => NewTagEntity, (tag) => tag.devices)
|
||||
@JoinTable({ name: 'device_tags' })
|
||||
public tags: NewTagEntity[];
|
||||
|
||||
constructor(partial: Partial<DeviceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
@ -3,7 +3,7 @@ import { SceneDto, SceneIconDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SceneIconType } from '@app/common/constants/secne-icon-type.enum';
|
||||
import { SceneDeviceEntity } from '../../scene-device/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
|
||||
// Define SceneIconEntity before SceneEntity
|
||||
@Entity({ name: 'scene-icon' })
|
||||
|
@ -0,0 +1,39 @@
|
||||
import {
|
||||
IsUUID,
|
||||
IsInt,
|
||||
IsOptional,
|
||||
ValidateNested,
|
||||
IsArray,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { SpaceModelDto } from '../../space-model/dtos/space-model.dto';
|
||||
import { ProductDto } from '../../product/dtos/product.dto';
|
||||
import { NewTagDto } from '../../tag/dtos/tag.dto';
|
||||
import { SpaceProductAllocationDto } from '../../space/dtos/space-product-allocation.dto';
|
||||
|
||||
export class SpaceModelProductAllocationDto {
|
||||
@IsUUID()
|
||||
uuid: string;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => SpaceModelDto)
|
||||
spaceModel: SpaceModelDto;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => ProductDto)
|
||||
product: ProductDto;
|
||||
|
||||
@IsInt()
|
||||
allowedQuantity: number;
|
||||
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => NewTagDto)
|
||||
allowedTags: NewTagDto[];
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => SpaceProductAllocationDto)
|
||||
inheritedSpaceAllocations?: SpaceProductAllocationDto[];
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
import { IsUUID, IsInt, ValidateNested, IsArray } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { SubSpaceModelDto } from './subspace-model.dto';
|
||||
import { ProductDto } from '@app/common/modules/product/dtos';
|
||||
import { NewTagDto } from '@app/common/modules/tag/dtos';
|
||||
|
||||
export class SubspaceModelProductAllocationDto {
|
||||
@IsUUID()
|
||||
uuid: string;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => SubSpaceModelDto)
|
||||
subspaceModel: SubSpaceModelDto;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => ProductDto)
|
||||
product: ProductDto;
|
||||
|
||||
@IsInt()
|
||||
allowedQuantity: number;
|
||||
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => NewTagDto)
|
||||
allowedTags: NewTagDto[];
|
||||
}
|
@ -1,11 +1,19 @@
|
||||
import { Entity, Column, ManyToOne, ManyToMany, JoinTable, OneToMany } from 'typeorm';
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
ManyToOne,
|
||||
ManyToMany,
|
||||
JoinTable,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import { SpaceModelEntity } from './space-model.entity';
|
||||
import { NewTagEntity } from '../../tag/entities';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
import { NewTagEntity } from '../../tag/entities/tag.entity';
|
||||
import { ProductEntity } from '../../product/entities/product.entity';
|
||||
import { SpaceProductAllocationEntity } from '../../space/entities/space-product-allocation.entity';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
|
||||
@Entity({ name: 'space_model_product_allocation' })
|
||||
export class SpaceModelProductAllocationEntity {
|
||||
export class SpaceModelProductAllocationEntity extends AbstractEntity<SpaceModelProductAllocationEntity> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
@ -38,4 +46,9 @@ export class SpaceModelProductAllocationEntity {
|
||||
},
|
||||
)
|
||||
public inheritedSpaceAllocations: SpaceProductAllocationEntity[];
|
||||
|
||||
constructor(partial: Partial<SpaceModelProductAllocationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { SpaceModelDto } from '../dtos';
|
||||
import { SubspaceModelEntity } from './subspace-model';
|
||||
import { ProjectEntity } from '../../project/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { TagModel } from './tag-model.entity';
|
||||
import { SpaceModelProductAllocationEntity } from './space-model-product-allocation.entity';
|
||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
|
||||
@Entity({ name: 'space-model' })
|
||||
export class SpaceModelEntity extends AbstractEntity<SpaceModelDto> {
|
||||
|
@ -1,21 +1,12 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
ManyToOne,
|
||||
ManyToMany,
|
||||
JoinTable,
|
||||
Unique,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import { Entity, Column, ManyToOne, ManyToMany, JoinTable } from 'typeorm';
|
||||
import { SubspaceModelEntity } from './subspace-model.entity';
|
||||
|
||||
import { NewTagEntity } from '@app/common/modules/tag';
|
||||
import { ProductEntity } from '@app/common/modules/product/entities';
|
||||
import { SubspaceProductAllocationEntity } from '@app/common/modules/space';
|
||||
import { ProductEntity } from '@app/common/modules/product/entities/product.entity';
|
||||
import { NewTagEntity } from '@app/common/modules/tag/entities/tag.entity';
|
||||
import { SubspaceModelProductAllocationDto } from '../../dtos/subspace-model/subspace-model-product-allocation.dto';
|
||||
import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
|
||||
|
||||
@Entity({ name: 'subspace_model_product_allocation' })
|
||||
@Unique(['subspaceModel', 'product', 'allowedTags'])
|
||||
export class SubspaceModelProductAllocationEntity {
|
||||
export class SubspaceModelProductAllocationEntity extends AbstractEntity<SubspaceModelProductAllocationDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
@ -26,7 +17,10 @@ export class SubspaceModelProductAllocationEntity {
|
||||
@ManyToOne(
|
||||
() => SubspaceModelEntity,
|
||||
(subspaceModel) => subspaceModel.productAllocations,
|
||||
{ nullable: false, onDelete: 'CASCADE' },
|
||||
{
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
)
|
||||
public subspaceModel: SubspaceModelEntity;
|
||||
|
||||
@ -36,16 +30,12 @@ export class SubspaceModelProductAllocationEntity {
|
||||
@Column({ type: 'int', default: 1 })
|
||||
public allowedQuantity: number;
|
||||
|
||||
@ManyToMany(() => NewTagEntity)
|
||||
@ManyToMany(() => NewTagEntity, (tag) => tag.subspaceModelAllocations)
|
||||
@JoinTable({ name: 'subspace_model_product_tags' })
|
||||
public allowedTags: NewTagEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceProductAllocationEntity,
|
||||
(allocation) => allocation.inheritedFromModel,
|
||||
{
|
||||
cascade: true,
|
||||
},
|
||||
)
|
||||
public inheritedSubspaceAllocations: SubspaceProductAllocationEntity[];
|
||||
constructor(partial: Partial<SubspaceModelProductAllocationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.e
|
||||
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { SubSpaceModelDto } from '../../dtos';
|
||||
import { SpaceModelEntity } from '../space-model.entity';
|
||||
import { SubspaceEntity } from '@app/common/modules/space/entities';
|
||||
import { TagModel } from '../tag-model.entity';
|
||||
import { SubspaceModelProductAllocationEntity } from './subspace-model-product-allocation.entity';
|
||||
import { SubspaceEntity } from '@app/common/modules/space/entities/subspace/subspace.entity';
|
||||
|
||||
@Entity({ name: 'subspace-model' })
|
||||
export class SubspaceModelEntity extends AbstractEntity<SubSpaceModelDto> {
|
||||
|
@ -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';
|
@ -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,
|
||||
]),
|
||||
],
|
||||
})
|
||||
|
@ -1,12 +1,20 @@
|
||||
import { Entity, Column, ManyToOne, Unique, OneToMany } from 'typeorm';
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
ManyToOne,
|
||||
Unique,
|
||||
ManyToMany,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
import { ProjectEntity } from '../../project/entities';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { NewTagDto } from '../dtos/tag.dto';
|
||||
import { SpaceModelProductAllocationEntity } from '../../space-model/entities/space-model-product-allocation.entity';
|
||||
import { SubspaceProductAllocationEntity } from '../../space';
|
||||
import { SubspaceModelProductAllocationEntity } from '../../space-model/entities/subspace-model/subspace-model-product-allocation.entity';
|
||||
import { DeviceEntity } from '../../device/entities/device.entity';
|
||||
|
||||
@Entity({ name: 'tag' })
|
||||
@Entity({ name: 'new_tag' })
|
||||
@Unique(['name', 'project'])
|
||||
export class NewTagEntity extends AbstractEntity<NewTagDto> {
|
||||
@Column({
|
||||
@ -16,7 +24,11 @@ export class NewTagEntity extends AbstractEntity<NewTagDto> {
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column()
|
||||
@Column({
|
||||
type: 'varchar',
|
||||
length: 255,
|
||||
nullable: true,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@ManyToOne(() => ProductEntity, (product) => product.newTags, {
|
||||
@ -31,17 +43,20 @@ export class NewTagEntity extends AbstractEntity<NewTagDto> {
|
||||
})
|
||||
public project: ProjectEntity;
|
||||
|
||||
@OneToMany(
|
||||
@ManyToMany(
|
||||
() => SpaceModelProductAllocationEntity,
|
||||
(allocation) => allocation.allowedTags,
|
||||
)
|
||||
public spaceModelAllocations: SpaceModelProductAllocationEntity[];
|
||||
|
||||
@OneToMany(
|
||||
() => SubspaceProductAllocationEntity,
|
||||
@ManyToMany(
|
||||
() => SubspaceModelProductAllocationEntity,
|
||||
(allocation) => allocation.allowedTags,
|
||||
)
|
||||
public subspaceAllocations: SubspaceProductAllocationEntity[];
|
||||
public subspaceModelAllocations: SubspaceModelProductAllocationEntity[];
|
||||
|
||||
@OneToMany(() => DeviceEntity, (device) => device.tag)
|
||||
public devices: DeviceEntity[];
|
||||
|
||||
constructor(partial: Partial<NewTagEntity>) {
|
||||
super();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { NewTagEntity } from './entities';
|
||||
import { NewTagEntity } from './entities/tag.entity';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
|
@ -25,10 +25,10 @@ import { RegionEntity } from '../../region/entities';
|
||||
import { TimeZoneEntity } from '../../timezone/entities';
|
||||
import { OtpType } from '../../../../src/constants/otp-type.enum';
|
||||
import { RoleTypeEntity } from '../../role-type/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { VisitorPasswordEntity } from '../../visitor-password/entities';
|
||||
import { InviteUserEntity } from '../../Invite-user/entities';
|
||||
import { ProjectEntity } from '../../project/entities';
|
||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||
|
||||
@Entity({ name: 'user' })
|
||||
export class UserEntity extends AbstractEntity<UserDto> {
|
||||
|
@ -48,7 +48,6 @@ import { DeviceStatusFirebaseService } from '@app/common/firebase/devices-status
|
||||
import { DeviceStatuses } from '@app/common/constants/device-status.enum';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
import { BatteryStatus } from '@app/common/constants/battery-status.enum';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||
import { SceneService } from 'src/scene/services';
|
||||
import { AddAutomationDto } from 'src/automation/dtos';
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
@ -60,6 +59,7 @@ import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { DeleteSceneFromSceneDeviceDto } from '../dtos/delete.device.dto';
|
||||
import { DeviceEntity } from '@app/common/modules/device/entities';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceService {
|
||||
|
@ -20,7 +20,7 @@ import {
|
||||
import { CheckEmailDto } from '../dtos/check-email.dto';
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { EmailService } from '@app/common/util/email.service';
|
||||
import { SpaceEntity, SpaceRepository } from '@app/common/modules/space';
|
||||
import { SpaceRepository } from '@app/common/modules/space';
|
||||
import { ActivateCodeDto } from '../dtos/active-code.dto';
|
||||
import { UserSpaceService } from 'src/users/services';
|
||||
import { SpaceUserService } from 'src/space/services';
|
||||
@ -30,6 +30,7 @@ import {
|
||||
} from '../dtos/update.invite-user.dto';
|
||||
import { RoleTypeRepository } from '@app/common/modules/role-type/repositories';
|
||||
import { InviteUserEntity } from '@app/common/modules/Invite-user/entities';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
|
||||
@Injectable()
|
||||
export class InviteUserService {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { PropogateUpdateSpaceModelCommand } from '../commands';
|
||||
import { SpaceEntity, SpaceRepository } from '@app/common/modules/space';
|
||||
import { SpaceRepository } from '@app/common/modules/space';
|
||||
import { SubspaceRepository } from '@app/common/modules/space/repositories/subspace.repository';
|
||||
import {
|
||||
SpaceModelEntity,
|
||||
@ -14,6 +14,7 @@ import { TagModelService } from '../services';
|
||||
import { UpdatedSubspaceModelPayload } from '../interfaces';
|
||||
import { ModifyAction } from '@app/common/constants/modify-action.enum';
|
||||
import { ModifySubspaceDto } from 'src/space/dtos';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
|
||||
@CommandHandler(PropogateUpdateSpaceModelCommand)
|
||||
export class PropogateUpdateSpaceModelHandler
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { SpaceEntity } from '@app/common/modules/space';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
|
||||
export class DisableSpaceCommand {
|
||||
constructor(
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { SpaceEntity } from '@app/common/modules/space';
|
||||
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { DeviceService } from 'src/device/services';
|
||||
@ -11,6 +10,7 @@ import {
|
||||
SpaceSceneService,
|
||||
} from '../services';
|
||||
import { TagService } from '../services/tag';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
|
||||
@CommandHandler(DisableSpaceCommand)
|
||||
export class DisableSpaceHandler
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { SubspaceEntity } from '@app/common/modules/space';
|
||||
import { SubspaceEntity } from '@app/common/modules/space/entities/subspace/subspace.entity';
|
||||
|
||||
export interface ModifySubspacePayload {
|
||||
addedSubspaces?: SubspaceEntity[];
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { SpaceEntity, SpaceLinkEntity } from '@app/common/modules/space';
|
||||
import { SpaceLinkEntity } from '@app/common/modules/space/entities/space-link.entity';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
import { SpaceLinkRepository } from '@app/common/modules/space/repositories';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { QueryRunner } from 'typeorm';
|
||||
|
@ -5,9 +5,9 @@ import { SceneService } from '../../scene/services';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { GetSceneDto } from '../../scene/dtos';
|
||||
import { ValidationService } from './space-validation.service';
|
||||
import { SpaceEntity } from '@app/common/modules/space';
|
||||
import { QueryRunner } from 'typeorm';
|
||||
import { SceneEntity } from '@app/common/modules/scene/entities';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceSceneService {
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { CommunityService } from '../../community/services';
|
||||
@ -10,6 +9,7 @@ import {
|
||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
|
||||
@Injectable()
|
||||
export class ValidationService {
|
||||
|
@ -18,7 +18,6 @@ import {
|
||||
} from '../dtos';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||
import { generateRandomString } from '@app/common/helper/randomString';
|
||||
import { SpaceLinkService } from './space-link';
|
||||
import { SubSpaceService } from './subspace';
|
||||
@ -34,6 +33,7 @@ import { SpaceModelService } from 'src/space-model/services';
|
||||
import { DisableSpaceCommand } from '../commands';
|
||||
import { GetSpaceDto } from '../dtos/get.space.dto';
|
||||
import { removeCircularReferences } from '@app/common/helper/removeCircularReferences';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
@Injectable()
|
||||
export class SpaceService {
|
||||
constructor(
|
||||
|
@ -16,10 +16,7 @@ import {
|
||||
import { PageResponse } from '@app/common/dto/pagination.response.dto';
|
||||
import { SubspaceDto } from '@app/common/modules/space/dtos';
|
||||
import { In, QueryRunner } from 'typeorm';
|
||||
import {
|
||||
SpaceEntity,
|
||||
SubspaceEntity,
|
||||
} from '@app/common/modules/space/entities';
|
||||
|
||||
import { SubspaceModelEntity } from '@app/common/modules/space-model';
|
||||
import { ValidationService } from '../space-validation.service';
|
||||
import { SubspaceRepository } from '@app/common/modules/space/repositories/subspace.repository';
|
||||
@ -27,6 +24,8 @@ import { TagService } from '../tag';
|
||||
import { ModifyAction } from '@app/common/constants/modify-action.enum';
|
||||
import { SubspaceDeviceService } from './subspace-device.service';
|
||||
import { ModifyTagDto } from 'src/space/dtos/tag/modify-tag.dto';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
import { SubspaceEntity } from '@app/common/modules/space/entities/subspace/subspace.entity';
|
||||
|
||||
@Injectable()
|
||||
export class SubSpaceService {
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { ModifyAction } from '@app/common/constants/modify-action.enum';
|
||||
import {
|
||||
SpaceEntity,
|
||||
SubspaceEntity,
|
||||
TagEntity,
|
||||
TagRepository,
|
||||
} from '@app/common/modules/space';
|
||||
import { TagRepository } from '@app/common/modules/space';
|
||||
import { TagModel } from '@app/common/modules/space-model';
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||
import { SubspaceEntity } from '@app/common/modules/space/entities/subspace/subspace.entity';
|
||||
import { TagEntity } from '@app/common/modules/space/entities/tag.entity';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { ProductService } from 'src/product/services';
|
||||
import { CreateTagDto, ModifySubspaceDto } from 'src/space/dtos';
|
||||
|
Reference in New Issue
Block a user