mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-11 07:38:49 +00:00
cleaned space entities
This commit is contained in:
@ -12,6 +12,7 @@ import {
|
|||||||
SpaceEntity,
|
SpaceEntity,
|
||||||
SpaceLinkEntity,
|
SpaceLinkEntity,
|
||||||
SubspaceEntity,
|
SubspaceEntity,
|
||||||
|
TagEntity,
|
||||||
} from '../modules/space/entities';
|
} from '../modules/space/entities';
|
||||||
import { UserSpaceEntity } from '../modules/user/entities';
|
import { UserSpaceEntity } from '../modules/user/entities';
|
||||||
import { DeviceUserPermissionEntity } from '../modules/device/entities';
|
import { DeviceUserPermissionEntity } from '../modules/device/entities';
|
||||||
@ -61,6 +62,7 @@ import {
|
|||||||
SpaceEntity,
|
SpaceEntity,
|
||||||
SpaceLinkEntity,
|
SpaceLinkEntity,
|
||||||
SubspaceEntity,
|
SubspaceEntity,
|
||||||
|
TagEntity,
|
||||||
UserSpaceEntity,
|
UserSpaceEntity,
|
||||||
DeviceUserPermissionEntity,
|
DeviceUserPermissionEntity,
|
||||||
RoleTypeEntity,
|
RoleTypeEntity,
|
||||||
|
@ -3,7 +3,7 @@ import { ProductDto } from '../dtos';
|
|||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { DeviceEntity } from '../../device/entities';
|
import { DeviceEntity } from '../../device/entities';
|
||||||
import { TagModel } from '../../space-model';
|
import { TagModel } from '../../space-model';
|
||||||
|
import { TagEntity } from '../../space/entities/tag.entity';
|
||||||
@Entity({ name: 'product' })
|
@Entity({ name: 'product' })
|
||||||
export class ProductEntity extends AbstractEntity<ProductDto> {
|
export class ProductEntity extends AbstractEntity<ProductDto> {
|
||||||
@Column({
|
@Column({
|
||||||
@ -30,6 +30,9 @@ export class ProductEntity extends AbstractEntity<ProductDto> {
|
|||||||
@OneToMany(() => TagModel, (tag) => tag.product)
|
@OneToMany(() => TagModel, (tag) => tag.product)
|
||||||
tagModels: TagModel[];
|
tagModels: TagModel[];
|
||||||
|
|
||||||
|
@OneToMany(() => TagEntity, (tag) => tag.product)
|
||||||
|
tags: TagEntity[];
|
||||||
|
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
() => DeviceEntity,
|
() => DeviceEntity,
|
||||||
(devicesProductEntity) => devicesProductEntity.productDevice,
|
(devicesProductEntity) => devicesProductEntity.productDevice,
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
import { Column, Entity, JoinColumn, ManyToOne, Unique } from 'typeorm';
|
import {
|
||||||
|
Column,
|
||||||
|
Entity,
|
||||||
|
JoinColumn,
|
||||||
|
ManyToOne,
|
||||||
|
OneToMany,
|
||||||
|
Unique,
|
||||||
|
} from 'typeorm';
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { TagModelDto } from '../dtos/tag-model.dto';
|
import { TagModelDto } from '../dtos/tag-model.dto';
|
||||||
import { SpaceModelEntity } from './space-model.entity';
|
import { SpaceModelEntity } from './space-model.entity';
|
||||||
import { SubspaceModelEntity } from './subspace-model';
|
import { SubspaceModelEntity } from './subspace-model';
|
||||||
import { ProductEntity } from '../../product/entities';
|
import { ProductEntity } from '../../product/entities';
|
||||||
|
import { TagEntity } from '../../space/entities/tag.entity';
|
||||||
|
|
||||||
@Entity({ name: 'tag_model' })
|
@Entity({ name: 'tag_model' })
|
||||||
@Unique(['tag', 'product', 'spaceModel', 'subspaceModel'])
|
@Unique(['tag', 'product', 'spaceModel', 'subspaceModel'])
|
||||||
@ -18,13 +26,13 @@ export class TagModel extends AbstractEntity<TagModelDto> {
|
|||||||
product: ProductEntity;
|
product: ProductEntity;
|
||||||
|
|
||||||
@ManyToOne(() => SpaceModelEntity, (space) => space.tags, { nullable: true })
|
@ManyToOne(() => SpaceModelEntity, (space) => space.tags, { nullable: true })
|
||||||
@JoinColumn({ name: 'space_id' })
|
@JoinColumn({ name: 'space_model_id' })
|
||||||
spaceModel: SpaceModelEntity;
|
spaceModel: SpaceModelEntity;
|
||||||
|
|
||||||
@ManyToOne(() => SubspaceModelEntity, (subspace) => subspace.tags, {
|
@ManyToOne(() => SubspaceModelEntity, (subspace) => subspace.tags, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
@JoinColumn({ name: 'subspace_id' })
|
@JoinColumn({ name: 'subspace_model_id' })
|
||||||
subspaceModel: SubspaceModelEntity;
|
subspaceModel: SubspaceModelEntity;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
@ -32,4 +40,7 @@ export class TagModel extends AbstractEntity<TagModelDto> {
|
|||||||
default: false,
|
default: false,
|
||||||
})
|
})
|
||||||
public disabled: boolean;
|
public disabled: boolean;
|
||||||
|
|
||||||
|
@OneToMany(() => TagEntity, (tag) => tag.model)
|
||||||
|
tags: TagEntity[];
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export * from './space.dto';
|
export * from './space.dto';
|
||||||
export * from './subspace.dto';
|
export * from './subspace.dto';
|
||||||
|
export * from './tag.dto';
|
||||||
|
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,3 +1,4 @@
|
|||||||
export * from './space.entity';
|
export * from './space.entity';
|
||||||
export * from './subspace';
|
export * from './subspace';
|
||||||
export * from './space-link.entity';
|
export * from './space-link.entity';
|
||||||
|
export * from './tag.entity';
|
||||||
|
@ -16,6 +16,7 @@ import { SpaceLinkEntity } from './space-link.entity';
|
|||||||
import { SceneEntity } from '../../scene/entities';
|
import { SceneEntity } from '../../scene/entities';
|
||||||
import { SpaceModelEntity } from '../../space-model';
|
import { SpaceModelEntity } from '../../space-model';
|
||||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||||
|
import { TagEntity } from './tag.entity';
|
||||||
|
|
||||||
@Entity({ name: 'space' })
|
@Entity({ name: 'space' })
|
||||||
@Unique(['invitationCode'])
|
@Unique(['invitationCode'])
|
||||||
@ -111,6 +112,10 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
|||||||
(inviteUserSpace) => inviteUserSpace.space,
|
(inviteUserSpace) => inviteUserSpace.space,
|
||||||
)
|
)
|
||||||
invitedUsers: InviteUserSpaceEntity[];
|
invitedUsers: InviteUserSpaceEntity[];
|
||||||
|
|
||||||
|
@OneToMany(() => TagEntity, (tag) => tag.space)
|
||||||
|
tags: TagEntity[];
|
||||||
|
|
||||||
constructor(partial: Partial<SpaceEntity>) {
|
constructor(partial: Partial<SpaceEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
@ -4,6 +4,7 @@ import { SubspaceModelEntity } from '@app/common/modules/space-model';
|
|||||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||||
import { SubspaceDto } from '../../dtos';
|
import { SubspaceDto } from '../../dtos';
|
||||||
import { SpaceEntity } from '../space.entity';
|
import { SpaceEntity } from '../space.entity';
|
||||||
|
import { TagEntity } from '../tag.entity';
|
||||||
|
|
||||||
@Entity({ name: 'subspace' })
|
@Entity({ name: 'subspace' })
|
||||||
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
||||||
@ -40,6 +41,9 @@ export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
|
|||||||
@JoinColumn({ name: 'subspace_model_uuid' })
|
@JoinColumn({ name: 'subspace_model_uuid' })
|
||||||
subSpaceModel?: SubspaceModelEntity;
|
subSpaceModel?: SubspaceModelEntity;
|
||||||
|
|
||||||
|
@OneToMany(() => TagEntity, (tag) => tag.subspace)
|
||||||
|
tags: TagEntity[];
|
||||||
|
|
||||||
constructor(partial: Partial<SubspaceEntity>) {
|
constructor(partial: Partial<SubspaceEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
39
libs/common/src/modules/space/entities/tag.entity.ts
Normal file
39
libs/common/src/modules/space/entities/tag.entity.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { Entity, Column, ManyToOne, JoinColumn, Unique } 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';
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { DataSource, Repository } from 'typeorm';
|
import { DataSource, Repository } from 'typeorm';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { SpaceEntity, SpaceLinkEntity } from '../entities';
|
import { SpaceEntity, SpaceLinkEntity, TagEntity } from '../entities';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SpaceRepository extends Repository<SpaceEntity> {
|
export class SpaceRepository extends Repository<SpaceEntity> {
|
||||||
@ -15,3 +15,10 @@ export class SpaceLinkRepository extends Repository<SpaceLinkEntity> {
|
|||||||
super(SpaceLinkEntity, dataSource.createEntityManager());
|
super(SpaceLinkEntity, dataSource.createEntityManager());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class TagRepository extends Repository<TagEntity> {
|
||||||
|
constructor(private dataSource: DataSource) {
|
||||||
|
super(TagEntity, dataSource.createEntityManager());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { SpaceEntity, SubspaceEntity } from './entities';
|
import { SpaceEntity, SubspaceEntity, TagEntity } from './entities';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [],
|
providers: [],
|
||||||
exports: [],
|
exports: [],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
imports: [TypeOrmModule.forFeature([SpaceEntity, SubspaceEntity])],
|
imports: [TypeOrmModule.forFeature([SpaceEntity, SubspaceEntity, TagEntity])],
|
||||||
})
|
})
|
||||||
export class SpaceRepositoryModule {}
|
export class SpaceRepositoryModule {}
|
||||||
|
@ -9,7 +9,6 @@ import {
|
|||||||
AddSpaceDto,
|
AddSpaceDto,
|
||||||
CommunitySpaceParam,
|
CommunitySpaceParam,
|
||||||
GetSpaceParam,
|
GetSpaceParam,
|
||||||
ProductAssignmentDto,
|
|
||||||
UpdateSpaceDto,
|
UpdateSpaceDto,
|
||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
@ -37,8 +36,7 @@ export class SpaceService {
|
|||||||
addSpaceDto: AddSpaceDto,
|
addSpaceDto: AddSpaceDto,
|
||||||
params: CommunitySpaceParam,
|
params: CommunitySpaceParam,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
const { parentUuid, direction, products, spaceModelUuid, subspaces } =
|
const { parentUuid, direction, spaceModelUuid, subspaces } = addSpaceDto;
|
||||||
addSpaceDto;
|
|
||||||
const { communityUuid, projectUuid } = params;
|
const { communityUuid, projectUuid } = params;
|
||||||
|
|
||||||
if (addSpaceDto.spaceName === ORPHAN_SPACE_NAME) {
|
if (addSpaceDto.spaceName === ORPHAN_SPACE_NAME) {
|
||||||
@ -58,7 +56,7 @@ export class SpaceService {
|
|||||||
projectUuid,
|
projectUuid,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.validateSpaceCreation(spaceModelUuid, products, subspaces);
|
this.validateSpaceCreation(spaceModelUuid);
|
||||||
|
|
||||||
const parent = parentUuid
|
const parent = parentUuid
|
||||||
? await this.validationService.validateSpace(parentUuid)
|
? await this.validationService.validateSpace(parentUuid)
|
||||||
@ -246,7 +244,7 @@ export class SpaceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If a parentId is provided, check if the parent exists
|
// If a parentId is provided, check if the parent exists
|
||||||
const { parentUuid, products } = updateSpaceDto;
|
const { parentUuid } = updateSpaceDto;
|
||||||
const parent = parentUuid
|
const parent = parentUuid
|
||||||
? await this.validationService.validateSpace(parentUuid)
|
? await this.validationService.validateSpace(parentUuid)
|
||||||
: null;
|
: null;
|
||||||
@ -257,8 +255,6 @@ export class SpaceService {
|
|||||||
// Save the updated space
|
// Save the updated space
|
||||||
await queryRunner.manager.save(space);
|
await queryRunner.manager.save(space);
|
||||||
|
|
||||||
if (products && products.length > 0) {
|
|
||||||
}
|
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
|
|
||||||
return new SuccessResponseDto({
|
return new SuccessResponseDto({
|
||||||
@ -370,12 +366,8 @@ export class SpaceService {
|
|||||||
return rootSpaces;
|
return rootSpaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
private validateSpaceCreation(
|
private validateSpaceCreation(spaceModelUuid?: string) {
|
||||||
spaceModelUuid?: string,
|
if (spaceModelUuid) {
|
||||||
products?: ProductAssignmentDto[],
|
|
||||||
subSpaces?: CreateSubspaceModelDto[],
|
|
||||||
) {
|
|
||||||
if (spaceModelUuid && (products?.length || subSpaces?.length)) {
|
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'For space creation choose either space model or products and subspace',
|
'For space creation choose either space model or products and subspace',
|
||||||
HttpStatus.CONFLICT,
|
HttpStatus.CONFLICT,
|
||||||
|
Reference in New Issue
Block a user