mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-09 22:57:24 +00:00
Compare commits
5 Commits
5cf45c30f4
...
fix/comiss
Author | SHA1 | Date | |
---|---|---|---|
a8d33bbc52 | |||
09322c5b80 | |||
74d3620d0e | |||
83be80d9f6 | |||
2589e391ed |
@ -1,5 +1,6 @@
|
||||
import { PlatformType } from '@app/common/constants/platform-type.enum';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { UserEntity } from '@app/common/modules/user/entities';
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
@ -32,7 +33,7 @@ export class AuthService {
|
||||
pass: string,
|
||||
regionUuid?: string,
|
||||
platform?: PlatformType,
|
||||
): Promise<any> {
|
||||
): Promise<Omit<UserEntity, 'password'>> {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: {
|
||||
email,
|
||||
@ -70,8 +71,9 @@ export class AuthService {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { password, ...result } = user;
|
||||
return result;
|
||||
// const { password, ...result } = user;
|
||||
delete user.password;
|
||||
return user;
|
||||
}
|
||||
|
||||
async createSession(data): Promise<UserSessionEntity> {
|
||||
@ -114,6 +116,7 @@ export class AuthService {
|
||||
hasAcceptedWebAgreement: user.hasAcceptedWebAgreement,
|
||||
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
||||
project: user?.project,
|
||||
bookingPoints: user?.bookingPoints,
|
||||
};
|
||||
if (payload.googleCode) {
|
||||
const profile = await this.getProfile(payload.googleCode);
|
||||
|
@ -220,6 +220,11 @@ export class ControllerRoute {
|
||||
public static readonly UPDATE_SPACE_DESCRIPTION =
|
||||
'Updates a space by its UUID and community ID. You can update the name, parent space, and other properties. If a parent space is provided and not already a parent, its `isParent` flag will be set to true.';
|
||||
|
||||
public static readonly UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_SUMMARY =
|
||||
'Update the order of child spaces under a specific parent space';
|
||||
public static readonly UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_DESCRIPTION =
|
||||
'Updates the order of child spaces under a specific parent space. You can provide a new order for the child spaces.';
|
||||
|
||||
public static readonly GET_HEIRARCHY_SUMMARY = 'Get space hierarchy';
|
||||
public static readonly GET_HEIRARCHY_DESCRIPTION =
|
||||
'This endpoint retrieves the hierarchical structure of spaces under a given space ID. It returns all the child spaces nested within the specified space, organized by their parent-child relationships. ';
|
||||
|
@ -1,3 +0,0 @@
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
|
||||
export class SpaceLinkEntity extends AbstractEntity {}
|
@ -6,9 +6,9 @@ import {
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
} from 'typeorm';
|
||||
import { SpaceDto } from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { AqiSpaceDailyPollutantStatsEntity } from '../../aqi/entities';
|
||||
import { BookableSpaceEntity } from '../../booking/entities';
|
||||
import { CommunityEntity } from '../../community/entities';
|
||||
import { DeviceEntity } from '../../device/entities';
|
||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||
@ -17,9 +17,9 @@ import { PresenceSensorDailySpaceEntity } from '../../presence-sensor/entities';
|
||||
import { SceneEntity } from '../../scene/entities';
|
||||
import { SpaceModelEntity } from '../../space-model';
|
||||
import { UserSpaceEntity } from '../../user/entities';
|
||||
import { SpaceDto } from '../dtos';
|
||||
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
||||
import { SubspaceEntity } from './subspace/subspace.entity';
|
||||
import { BookableSpaceEntity } from '../../booking/entities';
|
||||
|
||||
@Entity({ name: 'space' })
|
||||
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
@ -64,6 +64,12 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
})
|
||||
public disabled: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: Number,
|
||||
})
|
||||
public order?: number;
|
||||
|
||||
@OneToMany(() => SubspaceEntity, (subspace) => subspace.space, {
|
||||
nullable: true,
|
||||
})
|
||||
|
@ -11,9 +11,6 @@ export class SpaceRepository extends Repository<SpaceEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SpaceLinkRepository {}
|
||||
|
||||
@Injectable()
|
||||
export class InviteSpaceRepository extends Repository<InviteSpaceEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
|
@ -82,6 +82,12 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
||||
})
|
||||
public isActive: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: Number,
|
||||
})
|
||||
public bookingPoints?: number;
|
||||
|
||||
@Column({ default: false })
|
||||
hasAcceptedWebAgreement: boolean;
|
||||
|
||||
|
@ -1,25 +1,25 @@
|
||||
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { differenceInSeconds } from '@app/common/helper/differenceInSeconds';
|
||||
import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import { UserSignUpDto } from '../dtos/user-auth.dto';
|
||||
import { HelperHashService } from '../../../libs/common/src/helper/services';
|
||||
import { UserLoginDto } from '../dtos/user-login.dto';
|
||||
import { AuthService } from '../../../libs/common/src/auth/services/auth.service';
|
||||
import { UserSessionRepository } from '../../../libs/common/src/modules/session/repositories/session.repository';
|
||||
import { UserOtpRepository } from '../../../libs/common/src/modules/user/repositories/user.repository';
|
||||
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
|
||||
import { EmailService } from '../../../libs/common/src/util/email.service';
|
||||
import { OtpType } from '../../../libs/common/src/constants/otp-type.enum';
|
||||
import { UserEntity } from '../../../libs/common/src/modules/user/entities/user.entity';
|
||||
import * as argon2 from 'argon2';
|
||||
import { differenceInSeconds } from '@app/common/helper/differenceInSeconds';
|
||||
import { LessThan, MoreThan } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import * as argon2 from 'argon2';
|
||||
import { RoleService } from 'src/role/services';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { LessThan, MoreThan } from 'typeorm';
|
||||
import { AuthService } from '../../../libs/common/src/auth/services/auth.service';
|
||||
import { OtpType } from '../../../libs/common/src/constants/otp-type.enum';
|
||||
import { HelperHashService } from '../../../libs/common/src/helper/services';
|
||||
import { UserSessionRepository } from '../../../libs/common/src/modules/session/repositories/session.repository';
|
||||
import { UserEntity } from '../../../libs/common/src/modules/user/entities/user.entity';
|
||||
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
||||
import { UserOtpRepository } from '../../../libs/common/src/modules/user/repositories/user.repository';
|
||||
import { EmailService } from '../../../libs/common/src/util/email.service';
|
||||
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
|
||||
import { UserSignUpDto } from '../dtos/user-auth.dto';
|
||||
import { UserLoginDto } from '../dtos/user-login.dto';
|
||||
|
||||
@Injectable()
|
||||
export class UserAuthService {
|
||||
@ -108,7 +108,7 @@ export class UserAuthService {
|
||||
|
||||
async userLogin(data: UserLoginDto) {
|
||||
try {
|
||||
let user;
|
||||
let user: Omit<UserEntity, 'password'>;
|
||||
if (data.googleCode) {
|
||||
const googleUserData = await this.authService.login({
|
||||
googleCode: data.googleCode,
|
||||
@ -145,7 +145,7 @@ export class UserAuthService {
|
||||
}
|
||||
const session = await Promise.all([
|
||||
await this.sessionRepository.update(
|
||||
{ userId: user.id },
|
||||
{ userId: user?.['id'] },
|
||||
{
|
||||
isLoggedOut: true,
|
||||
},
|
||||
@ -166,6 +166,7 @@ export class UserAuthService {
|
||||
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
||||
project: user.project,
|
||||
sessionId: session[1].uuid,
|
||||
bookingPoints: user.bookingPoints,
|
||||
});
|
||||
return res;
|
||||
} catch (error) {
|
||||
@ -347,6 +348,7 @@ export class UserAuthService {
|
||||
userId: user.uuid,
|
||||
uuid: user.uuid,
|
||||
type,
|
||||
bookingPoints: user.bookingPoints,
|
||||
sessionId,
|
||||
});
|
||||
await this.authService.updateRefreshToken(user.uuid, tokens.refreshToken);
|
||||
|
@ -5,7 +5,6 @@ import { ConfigModule } from '@nestjs/config';
|
||||
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
||||
import {
|
||||
InviteSpaceRepository,
|
||||
SpaceLinkRepository,
|
||||
SpaceProductAllocationRepository,
|
||||
SpaceRepository,
|
||||
} from '@app/common/modules/space/repositories';
|
||||
@ -16,14 +15,12 @@ import { CommunityRepository } from '@app/common/modules/community/repositories'
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||
import {
|
||||
SpaceLinkService,
|
||||
SpaceService,
|
||||
SubspaceDeviceService,
|
||||
SubSpaceService,
|
||||
ValidationService,
|
||||
} from 'src/space/services';
|
||||
import { TagService as NewTagService } from 'src/tags/services';
|
||||
import { TagService } from 'src/space/services/tag';
|
||||
import {
|
||||
SpaceModelService,
|
||||
SubSpaceModelService,
|
||||
@ -81,16 +78,13 @@ import { AqiSpaceDailyPollutantStatsRepository } from '@app/common/modules/aqi/r
|
||||
SpaceService,
|
||||
InviteSpaceRepository,
|
||||
// Todo: find out why this is needed
|
||||
SpaceLinkService,
|
||||
SubSpaceService,
|
||||
ValidationService,
|
||||
NewTagService,
|
||||
SpaceModelService,
|
||||
SpaceProductAllocationService,
|
||||
SpaceLinkRepository,
|
||||
SubspaceRepository,
|
||||
// Todo: find out why this is needed
|
||||
TagService,
|
||||
SubspaceDeviceService,
|
||||
SubspaceProductAllocationService,
|
||||
SpaceModelRepository,
|
||||
|
@ -323,7 +323,7 @@ export class DeviceService {
|
||||
|
||||
async addNewDevice(addDeviceDto: AddDeviceDto, projectUuid: string) {
|
||||
try {
|
||||
const device = await this.getDeviceDetailsByDeviceIdTuya(
|
||||
const device = await this.getNewDeviceDetailsFromTuya(
|
||||
addDeviceDto.deviceTuyaUuid,
|
||||
);
|
||||
|
||||
@ -349,6 +349,7 @@ export class DeviceService {
|
||||
spaceDevice: { uuid: addDeviceDto.spaceUuid },
|
||||
tag: { uuid: addDeviceDto.tagUuid },
|
||||
name: addDeviceDto.deviceName,
|
||||
deviceTuyaConstUuid: device.uuid,
|
||||
});
|
||||
if (deviceSaved.uuid) {
|
||||
const deviceStatus: BaseResponseDto =
|
||||
@ -752,6 +753,45 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async getNewDeviceDetailsFromTuya(
|
||||
deviceId: string,
|
||||
): Promise<GetDeviceDetailsInterface> {
|
||||
console.log('fetching device details from Tuya for deviceId:', deviceId);
|
||||
try {
|
||||
const result = await this.tuyaService.getDeviceDetails(deviceId);
|
||||
|
||||
if (!result) {
|
||||
throw new NotFoundException('Device not found');
|
||||
}
|
||||
// Convert keys to camel case
|
||||
const camelCaseResponse = convertKeysToCamelCase(result);
|
||||
|
||||
const product = await this.productRepository.findOne({
|
||||
where: { prodId: camelCaseResponse.productId },
|
||||
});
|
||||
|
||||
if (!product) {
|
||||
throw new NotFoundException('Product Type is not supported');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { productId, id, productName, ...rest } = camelCaseResponse;
|
||||
|
||||
return {
|
||||
...rest,
|
||||
productUuid: product.uuid,
|
||||
productName: product.name,
|
||||
} as GetDeviceDetailsInterface;
|
||||
} catch (error) {
|
||||
console.log('error', error);
|
||||
|
||||
throw new HttpException(
|
||||
error.message || 'Error fetching device details from Tuya',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
async getDeviceInstructionByDeviceId(
|
||||
deviceUuid: string,
|
||||
projectUuid: string,
|
||||
|
@ -38,7 +38,6 @@ import {
|
||||
} from '@app/common/modules/scene/repositories';
|
||||
import {
|
||||
InviteSpaceRepository,
|
||||
SpaceLinkRepository,
|
||||
SpaceProductAllocationRepository,
|
||||
SpaceRepository,
|
||||
} from '@app/common/modules/space';
|
||||
@ -121,7 +120,6 @@ import { AqiSpaceDailyPollutantStatsRepository } from '@app/common/modules/aqi/r
|
||||
NewTagService,
|
||||
SpaceModelService,
|
||||
SpaceProductAllocationService,
|
||||
SpaceLinkRepository,
|
||||
SubspaceRepository,
|
||||
SubspaceDeviceService,
|
||||
SubspaceProductAllocationService,
|
||||
|
@ -22,7 +22,6 @@ import {
|
||||
} from '@app/common/modules/scene/repositories';
|
||||
import {
|
||||
InviteSpaceRepository,
|
||||
SpaceLinkRepository,
|
||||
SpaceProductAllocationRepository,
|
||||
SpaceRepository,
|
||||
} from '@app/common/modules/space';
|
||||
@ -96,7 +95,6 @@ import { AqiSpaceDailyPollutantStatsRepository } from '@app/common/modules/aqi/r
|
||||
SpaceModelService,
|
||||
SpaceProductAllocationService,
|
||||
SqlLoaderService,
|
||||
SpaceLinkRepository,
|
||||
SubspaceRepository,
|
||||
SubspaceDeviceService,
|
||||
SubspaceProductAllocationService,
|
||||
|
@ -23,7 +23,6 @@ import {
|
||||
} from '@app/common/modules/scene/repositories';
|
||||
import {
|
||||
InviteSpaceRepository,
|
||||
SpaceLinkRepository,
|
||||
SpaceProductAllocationRepository,
|
||||
SpaceRepository,
|
||||
} from '@app/common/modules/space';
|
||||
@ -94,7 +93,6 @@ const CommandHandlers = [CreateOrphanSpaceHandler];
|
||||
SpaceModelService,
|
||||
DeviceService,
|
||||
SpaceProductAllocationService,
|
||||
SpaceLinkRepository,
|
||||
SubspaceRepository,
|
||||
SubspaceDeviceService,
|
||||
SubspaceProductAllocationService,
|
||||
|
@ -22,7 +22,6 @@ import {
|
||||
} from '@app/common/modules/scene/repositories';
|
||||
import {
|
||||
InviteSpaceRepository,
|
||||
SpaceLinkRepository,
|
||||
SpaceProductAllocationRepository,
|
||||
SpaceRepository,
|
||||
} from '@app/common/modules/space';
|
||||
@ -93,7 +92,6 @@ const CommandHandlers = [
|
||||
DeviceRepository,
|
||||
TuyaService,
|
||||
CommunityRepository,
|
||||
SpaceLinkRepository,
|
||||
InviteSpaceRepository,
|
||||
NewTagService,
|
||||
DeviceService,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { SpaceService } from '../services';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
@ -12,12 +11,14 @@ import {
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { AddSpaceDto, CommunitySpaceParam, UpdateSpaceDto } from '../dtos';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { GetSpaceParam } from '../dtos/get.space.param';
|
||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||
import { AddSpaceDto, CommunitySpaceParam, UpdateSpaceDto } from '../dtos';
|
||||
import { GetSpaceDto } from '../dtos/get.space.dto';
|
||||
import { GetSpaceParam } from '../dtos/get.space.param';
|
||||
import { OrderSpacesDto } from '../dtos/order.spaces.dto';
|
||||
import { SpaceService } from '../services';
|
||||
|
||||
@ApiTags('Space Module')
|
||||
@Controller({
|
||||
@ -65,6 +66,26 @@ export class SpaceController {
|
||||
);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('SPACE_UPDATE')
|
||||
@ApiOperation({
|
||||
summary:
|
||||
ControllerRoute.SPACE.ACTIONS
|
||||
.UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.SPACE.ACTIONS
|
||||
.UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_DESCRIPTION,
|
||||
})
|
||||
@Post(':parentSpaceUuid/spaces/order')
|
||||
async updateSpacesOrder(
|
||||
@Body() orderSpacesDto: OrderSpacesDto,
|
||||
@Param() communitySpaceParam: CommunitySpaceParam,
|
||||
@Param('parentSpaceUuid') parentSpaceUuid: string,
|
||||
) {
|
||||
return this.spaceService.updateSpacesOrder(parentSpaceUuid, orderSpacesDto);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('SPACE_DELETE')
|
||||
|
13
src/space/dtos/order.spaces.dto.ts
Normal file
13
src/space/dtos/order.spaces.dto.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ArrayUnique, IsNotEmpty, IsUUID } from 'class-validator';
|
||||
|
||||
export class OrderSpacesDto {
|
||||
@ApiProperty({
|
||||
description: 'List of children spaces associated with the space',
|
||||
type: [String],
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@ArrayUnique()
|
||||
@IsUUID('4', { each: true, message: 'Invalid space UUID provided' })
|
||||
spacesUuids: string[];
|
||||
}
|
@ -2,6 +2,7 @@ import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
ArrayUnique,
|
||||
IsArray,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
@ -49,6 +50,20 @@ export class UpdateSpaceDto {
|
||||
description: 'List of subspace modifications',
|
||||
type: [UpdateSubspaceDto],
|
||||
})
|
||||
@ArrayUnique((subspace) => subspace.subspaceName, {
|
||||
message(validationArguments) {
|
||||
const subspaces = validationArguments.value;
|
||||
const nameCounts = subspaces.reduce((acc, curr) => {
|
||||
acc[curr.subspaceName] = (acc[curr.subspaceName] || 0) + 1;
|
||||
return acc;
|
||||
}, {});
|
||||
// Find duplicates
|
||||
const duplicates = Object.keys(nameCounts).filter(
|
||||
(name) => nameCounts[name] > 1,
|
||||
);
|
||||
return `Duplicate subspace names found: ${duplicates.join(', ')}`;
|
||||
},
|
||||
})
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
|
@ -2,6 +2,5 @@ export * from './space.service';
|
||||
export * from './space-user.service';
|
||||
export * from './space-device.service';
|
||||
export * from './subspace';
|
||||
export * from './space-link';
|
||||
export * from './space-scene.service';
|
||||
export * from './space-validation.service';
|
||||
|
@ -1 +0,0 @@
|
||||
export * from './space-link.service';
|
@ -1,6 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
// todo: find out why we need to import this
|
||||
// in community module in order for the whole system to work
|
||||
@Injectable()
|
||||
export class SpaceLinkService {}
|
@ -33,6 +33,7 @@ import {
|
||||
} from '../dtos';
|
||||
import { CreateProductAllocationDto } from '../dtos/create-product-allocation.dto';
|
||||
import { GetSpaceDto } from '../dtos/get.space.dto';
|
||||
import { OrderSpacesDto } from '../dtos/order.spaces.dto';
|
||||
import { SpaceWithParentsDto } from '../dtos/space.parents.dto';
|
||||
import { SpaceProductAllocationService } from './space-product-allocation.service';
|
||||
import { ValidationService } from './space-validation.service';
|
||||
@ -355,6 +356,32 @@ export class SpaceService {
|
||||
}
|
||||
}
|
||||
|
||||
async updateSpacesOrder(
|
||||
parentSpaceUuid: string,
|
||||
{ spacesUuids }: OrderSpacesDto,
|
||||
) {
|
||||
try {
|
||||
await this.spaceRepository.update(
|
||||
{ uuid: In(spacesUuids), parent: { uuid: parentSpaceUuid } },
|
||||
{
|
||||
order: () =>
|
||||
'CASE ' +
|
||||
spacesUuids
|
||||
.map((s, index) => `WHEN uuid = '${s}' THEN ${index + 1}`)
|
||||
.join(' ') +
|
||||
' END',
|
||||
},
|
||||
);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error updating spaces order:', error);
|
||||
throw new HttpException(
|
||||
'An error occurred while updating spaces order',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async delete(params: GetSpaceParam): Promise<BaseResponseDto> {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
@ -426,7 +453,7 @@ export class SpaceService {
|
||||
}
|
||||
}
|
||||
|
||||
async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) {
|
||||
private async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) {
|
||||
await this.commandBus.execute(
|
||||
new DisableSpaceCommand({ spaceUuid: space.uuid, orphanSpace }),
|
||||
);
|
||||
@ -709,10 +736,21 @@ export class SpaceService {
|
||||
rootSpaces.push(map.get(space.uuid)!); // Push only root spaces
|
||||
}
|
||||
});
|
||||
|
||||
rootSpaces.forEach(this.sortSpaceChildren.bind(this));
|
||||
return rootSpaces;
|
||||
}
|
||||
|
||||
private sortSpaceChildren(space: SpaceEntity) {
|
||||
if (space.children && space.children.length > 0) {
|
||||
space.children.sort((a, b) => {
|
||||
const aOrder = a.order ?? Infinity;
|
||||
const bOrder = b.order ?? Infinity;
|
||||
return aOrder - bOrder;
|
||||
});
|
||||
space.children.forEach(this.sortSpaceChildren.bind(this)); // Recursively sort children of children
|
||||
}
|
||||
}
|
||||
|
||||
private validateSpaceCreationCriteria({
|
||||
spaceModelUuid,
|
||||
productAllocations,
|
||||
|
@ -23,7 +23,7 @@ export class SubspaceProductAllocationService {
|
||||
// spaceAllocationsToExclude?: SpaceProductAllocationEntity[],
|
||||
): Promise<void> {
|
||||
try {
|
||||
if (!allocationsData.length) return;
|
||||
if (!allocationsData?.length) return;
|
||||
|
||||
const allocations: SubspaceProductAllocationEntity[] = [];
|
||||
|
||||
@ -112,7 +112,7 @@ export class SubspaceProductAllocationService {
|
||||
);
|
||||
|
||||
// Create the product-tag mapping based on the processed tags
|
||||
const productTagMapping = subspace.productAllocations.map(
|
||||
const productTagMapping = subspace.productAllocations?.map(
|
||||
({ tagUuid, tagName, productUuid }) => {
|
||||
const inputTag = tagUuid
|
||||
? createdTagsByUUID.get(tagUuid)
|
||||
|
@ -39,7 +39,7 @@ export class SubSpaceService {
|
||||
private readonly subspaceProductAllocationService: SubspaceProductAllocationService,
|
||||
) {}
|
||||
|
||||
async createSubspaces(
|
||||
private async createSubspaces(
|
||||
subspaceData: Array<{
|
||||
subspaceName: string;
|
||||
space: SpaceEntity;
|
||||
|
@ -1 +0,0 @@
|
||||
export * from './tag.service';
|
@ -1,8 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
// todo: find out why we need to import this
|
||||
// in community module in order for the whole system to work
|
||||
@Injectable()
|
||||
export class TagService {
|
||||
constructor() {}
|
||||
}
|
@ -37,7 +37,6 @@ import {
|
||||
} from '@app/common/modules/space-model';
|
||||
import {
|
||||
InviteSpaceRepository,
|
||||
SpaceLinkRepository,
|
||||
SpaceProductAllocationRepository,
|
||||
SpaceRepository,
|
||||
} from '@app/common/modules/space/repositories';
|
||||
@ -116,7 +115,6 @@ export const CommandHandlers = [DisableSpaceHandler];
|
||||
SubspaceRepository,
|
||||
DeviceRepository,
|
||||
CommunityRepository,
|
||||
SpaceLinkRepository,
|
||||
UserSpaceRepository,
|
||||
UserRepository,
|
||||
SpaceUserService,
|
||||
|
Reference in New Issue
Block a user