mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 20:24:54 +00:00
added space link entity
This commit is contained in:
@ -21,6 +21,7 @@ import { TimeZoneModule } from './timezone/timezone.module';
|
||||
import { VisitorPasswordModule } from './vistor-password/visitor-password.module';
|
||||
import { ScheduleModule } from './schedule/schedule.module';
|
||||
import { SpaceModule } from './space/space.module';
|
||||
import { ProductModule } from './product';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
@ -46,6 +47,7 @@ import { SpaceModule } from './space/space.module';
|
||||
TimeZoneModule,
|
||||
VisitorPasswordModule,
|
||||
ScheduleModule,
|
||||
ProductModule,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
IsUUID,
|
||||
@ -25,6 +26,10 @@ export class AddSpaceDto {
|
||||
@IsOptional()
|
||||
parentUuid?: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public icon: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Indicates whether the space is private or public',
|
||||
example: false,
|
||||
@ -32,6 +37,19 @@ export class AddSpaceDto {
|
||||
})
|
||||
@IsBoolean()
|
||||
isPrivate: boolean;
|
||||
|
||||
@ApiProperty({ description: 'X position on canvas', example: 120 })
|
||||
@IsNumber()
|
||||
x: number;
|
||||
|
||||
@ApiProperty({ description: 'Y position on canvas', example: 200 })
|
||||
@IsNumber()
|
||||
y: number;
|
||||
|
||||
@ApiProperty({ description: 'Y position on canvas', example: 200 })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
direction: string;
|
||||
}
|
||||
|
||||
export class AddUserSpaceDto {
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import {
|
||||
SpaceLinkRepository,
|
||||
SpaceRepository,
|
||||
} from '@app/common/modules/space/repositories';
|
||||
import {
|
||||
BadRequestException,
|
||||
HttpException,
|
||||
@ -16,6 +19,7 @@ import { generateRandomString } from '@app/common/helper/randomString';
|
||||
export class SpaceService {
|
||||
constructor(
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
private readonly spaceLinkRepository: SpaceLinkRepository,
|
||||
private readonly communityRepository: CommunityRepository,
|
||||
) {}
|
||||
|
||||
@ -25,7 +29,7 @@ export class SpaceService {
|
||||
): Promise<BaseResponseDto> {
|
||||
let parent: SpaceEntity | null = null;
|
||||
|
||||
const { parentUuid } = addSpaceDto;
|
||||
const { parentUuid, direction } = addSpaceDto;
|
||||
const community = await this.communityRepository.findOne({
|
||||
where: { uuid: communityId },
|
||||
});
|
||||
@ -60,6 +64,16 @@ export class SpaceService {
|
||||
|
||||
await this.spaceRepository.save(newSpace);
|
||||
|
||||
if (direction && parent) {
|
||||
const spaceLink = await this.spaceLinkRepository.create({
|
||||
direction,
|
||||
endSpace: newSpace,
|
||||
startSpace: parent,
|
||||
});
|
||||
|
||||
await this.spaceLinkRepository.save(spaceLink);
|
||||
}
|
||||
|
||||
return new SuccessResponseDto({
|
||||
statusCode: HttpStatus.CREATED,
|
||||
data: newSpace,
|
||||
@ -88,7 +102,7 @@ export class SpaceService {
|
||||
// Get all spaces related to the community, including the parent-child relations
|
||||
const spaces = await this.spaceRepository.find({
|
||||
where: { community: { uuid: communityUuid } },
|
||||
relations: ['parent', 'children'], // Include parent and children relations
|
||||
relations: ['parent', 'children', 'incomingConnections'], // Include parent and children relations
|
||||
});
|
||||
|
||||
// Organize spaces into a hierarchical structure
|
||||
|
||||
@ -20,6 +20,7 @@ import {
|
||||
import {
|
||||
SpaceRepository,
|
||||
SubspaceRepository,
|
||||
SpaceLinkRepository,
|
||||
} from '@app/common/modules/space/repositories';
|
||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||
import {
|
||||
@ -59,6 +60,7 @@ import { DeviceStatusLogRepository } from '@app/common/modules/device-status-log
|
||||
DeviceRepository,
|
||||
CommunityRepository,
|
||||
SubspaceRepository,
|
||||
SpaceLinkRepository,
|
||||
UserSpaceRepository,
|
||||
UserRepository,
|
||||
SpaceUserService,
|
||||
|
||||
Reference in New Issue
Block a user