mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 04:57:55 +00:00
Fixed scene
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export * from './space.controller';
|
||||
export * from './space-user.controller';
|
||||
export * from './space-device.controller';
|
||||
export * from './space-scene.controller';
|
||||
export * from './subspace';
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { SpaceSceneService } from '../services';
|
||||
import { GetSceneDto } from '../../scene/dtos';
|
||||
import { GetSpaceParam } from '../dtos';
|
||||
|
||||
@ApiTags('Space Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: ControllerRoute.SPACE_SCENE.ROUTE,
|
||||
})
|
||||
export class SpaceSceneController {
|
||||
constructor(private readonly sceneService: SpaceSceneService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiOperation({
|
||||
summary:
|
||||
ControllerRoute.SPACE_SCENE.ACTIONS.GET_TAP_TO_RUN_SCENE_BY_SPACE_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.SPACE_SCENE.ACTIONS
|
||||
.GET_TAP_TO_RUN_SCENE_BY_SPACE_DESCRIPTION,
|
||||
})
|
||||
@Get()
|
||||
async getTapToRunSceneByUnit(
|
||||
@Param() params: GetSpaceParam,
|
||||
@Query() inHomePage: GetSceneDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.sceneService.getScenes(params, inHomePage);
|
||||
}
|
||||
}
|
||||
@@ -2,3 +2,4 @@ export * from './space.service';
|
||||
export * from './space-user.service';
|
||||
export * from './space-device.service';
|
||||
export * from './subspace';
|
||||
export * from './space-scene.service';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TuyaService } from '@app/common/integrations/tuya/tuya.service';
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
@@ -51,10 +51,7 @@ export class SpaceDeviceService {
|
||||
});
|
||||
}
|
||||
|
||||
private async validateCommunityAndSpace(
|
||||
communityUuid: string,
|
||||
spaceUuid: string,
|
||||
) {
|
||||
async validateCommunityAndSpace(communityUuid: string, spaceUuid: string) {
|
||||
const community = await this.communityRepository.findOne({
|
||||
where: { uuid: communityUuid },
|
||||
});
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import { GetSpaceParam } from '../dtos';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SpaceService } from './space.service';
|
||||
import { SceneService } from '../../scene/services';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { GetSceneDto } from '../../scene/dtos';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceSceneService {
|
||||
constructor(
|
||||
private readonly spaceSevice: SpaceService,
|
||||
private readonly sceneSevice: SceneService,
|
||||
) {}
|
||||
|
||||
async getScenes(
|
||||
params: GetSpaceParam,
|
||||
getSceneDto: GetSceneDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
try {
|
||||
const { spaceUuid, communityUuid } = params;
|
||||
|
||||
await this.spaceSevice.validateCommunityAndSpace(
|
||||
communityUuid,
|
||||
spaceUuid,
|
||||
);
|
||||
|
||||
const scenes = await this.sceneSevice.findScenesBySpace(
|
||||
spaceUuid,
|
||||
getSceneDto,
|
||||
);
|
||||
|
||||
return new SuccessResponseDto({
|
||||
message: `Scenes retrieved successfully for space ${spaceUuid}`,
|
||||
data: scenes,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error retrieving scenes:', error);
|
||||
|
||||
if (error instanceof BadRequestException) {
|
||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
'An error occurred while retrieving scenes',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,4 +357,29 @@ export class SpaceService {
|
||||
|
||||
return rootSpaces; // Return the root spaces with children nested within them
|
||||
}
|
||||
|
||||
async validateCommunityAndSpace(communityUuid: string, spaceUuid: string) {
|
||||
const community = await this.communityRepository.findOne({
|
||||
where: { uuid: communityUuid },
|
||||
});
|
||||
if (!community) {
|
||||
this.throwNotFound('Community', communityUuid);
|
||||
}
|
||||
|
||||
const space = await this.spaceRepository.findOne({
|
||||
where: { uuid: spaceUuid, community: { uuid: communityUuid } },
|
||||
relations: ['devices', 'devices.productDevice'],
|
||||
});
|
||||
if (!space) {
|
||||
this.throwNotFound('Space', spaceUuid);
|
||||
}
|
||||
return space;
|
||||
}
|
||||
|
||||
private throwNotFound(entity: string, uuid: string) {
|
||||
throw new HttpException(
|
||||
`${entity} with ID ${uuid} not found`,
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { DeviceSubSpaceParam, GetSubSpaceParam } from '../../dtos';
|
||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { TuyaService } from '@app/common/integrations/tuya/tuya.service';
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||
import { GetDeviceDetailsInterface } from '../../../device/interfaces/get.device.interface';
|
||||
|
||||
|
||||
@@ -7,9 +7,11 @@ import {
|
||||
SpaceUserController,
|
||||
SubSpaceController,
|
||||
SubSpaceDeviceController,
|
||||
SpaceSceneController,
|
||||
} from './controllers';
|
||||
import {
|
||||
SpaceDeviceService,
|
||||
SpaceSceneService,
|
||||
SpaceService,
|
||||
SpaceUserService,
|
||||
SubspaceDeviceService,
|
||||
@@ -25,8 +27,16 @@ import {
|
||||
UserSpaceRepository,
|
||||
} from '@app/common/modules/user/repositories';
|
||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||
import { TuyaService } from '@app/common/integrations/tuya/tuya.service';
|
||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||
import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||
import { SceneService } from '../scene/services';
|
||||
import {
|
||||
SceneIconRepository,
|
||||
SceneRepository,
|
||||
} from '@app/common/modules/scene/repositories';
|
||||
import { DeviceService } from 'src/device/services';
|
||||
import { DeviceStatusFirebaseService } from '@app/common/firebase/devices-status/services/devices-status.service';
|
||||
import { DeviceStatusLogRepository } from '@app/common/modules/device-status-log/repositories';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule, SpaceRepositoryModule],
|
||||
@@ -36,6 +46,7 @@ import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||
SpaceDeviceController,
|
||||
SubSpaceController,
|
||||
SubSpaceDeviceController,
|
||||
SpaceSceneController,
|
||||
],
|
||||
providers: [
|
||||
SpaceService,
|
||||
@@ -51,6 +62,13 @@ import { ProductRepository } from '@app/common/modules/product/repositories';
|
||||
UserSpaceRepository,
|
||||
UserRepository,
|
||||
SpaceUserService,
|
||||
SpaceSceneService,
|
||||
SceneService,
|
||||
SceneIconRepository,
|
||||
SceneRepository,
|
||||
DeviceService,
|
||||
DeviceStatusFirebaseService,
|
||||
DeviceStatusLogRepository,
|
||||
],
|
||||
exports: [SpaceService],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user