updated spaceUuid

This commit is contained in:
hannathkadher
2024-10-30 23:50:52 +04:00
parent 689d42cf1e
commit f1c07360cb
4 changed files with 23 additions and 15 deletions

View File

@ -47,7 +47,8 @@ export class SceneEntity extends AbstractEntity<SceneDto> {
@Column({ @Column({
nullable: false, nullable: false,
}) })
unitUuid: string; spaceUuid: string;
@Column({ @Column({
nullable: false, nullable: false,
}) })

View File

@ -192,10 +192,10 @@ export class AutomationService {
} }
} }
async getTapToRunSceneDetailsTuya( async getTapToRunSceneDetailsTuya(
sceneId: string, sceneUuid: string,
): Promise<AutomationDetailsResult> { ): Promise<AutomationDetailsResult> {
try { try {
const path = `/v2.0/cloud/scene/rule/${sceneId}`; const path = `/v2.0/cloud/scene/rule/${sceneUuid}`;
const response = await this.tuya.request({ const response = await this.tuya.request({
method: 'GET', method: 'GET',
path, path,

View File

@ -60,7 +60,7 @@ export class SceneController {
@ApiBearerAuth() @ApiBearerAuth()
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Delete('tap-to-run/:unitUuid/:sceneId') @Delete('tap-to-run/:unitUuid/:sceneUuid')
async deleteTapToRunScene(@Param() param: DeleteSceneParamDto) { async deleteTapToRunScene(@Param() param: DeleteSceneParamDto) {
await this.sceneService.deleteTapToRunScene(param); await this.sceneService.deleteTapToRunScene(param);
return { return {
@ -70,7 +70,7 @@ export class SceneController {
} }
@ApiBearerAuth() @ApiBearerAuth()
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('tap-to-run/trigger/:sceneId') @Post('tap-to-run/trigger/:sceneUuid')
async triggerTapToRunScene(@Param() param: SceneParamDto) { async triggerTapToRunScene(@Param() param: SceneParamDto) {
await this.sceneService.triggerTapToRunScene(param.sceneUuid); await this.sceneService.triggerTapToRunScene(param.sceneUuid);
return { return {
@ -82,7 +82,7 @@ export class SceneController {
@ApiBearerAuth() @ApiBearerAuth()
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Get('tap-to-run/details/:sceneId') @Get('tap-to-run/details/:sceneUuid')
async getTapToRunSceneDetails(@Param() param: SceneParamDto) { async getTapToRunSceneDetails(@Param() param: SceneParamDto) {
const tapToRunScenes = await this.sceneService.getTapToRunSceneDetails( const tapToRunScenes = await this.sceneService.getTapToRunSceneDetails(
param.sceneUuid, param.sceneUuid,
@ -92,7 +92,7 @@ export class SceneController {
@ApiBearerAuth() @ApiBearerAuth()
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Put('tap-to-run/:sceneId') @Put('tap-to-run/:sceneUuid')
async updateTapToRunScene( async updateTapToRunScene(
@Body() updateSceneTapToRunDto: UpdateSceneTapToRunDto, @Body() updateSceneTapToRunDto: UpdateSceneTapToRunDto,
@Param() param: SceneParamDto, @Param() param: SceneParamDto,
@ -108,6 +108,7 @@ export class SceneController {
data: tapToRunScene, data: tapToRunScene,
}; };
} }
@ApiBearerAuth() @ApiBearerAuth()
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('icon') @Post('icon')

View File

@ -113,7 +113,7 @@ export class SceneService {
: defaultSceneIcon.uuid, : defaultSceneIcon.uuid,
}, },
showInHomePage: addSceneTapToRunDto.showInHomePage, showInHomePage: addSceneTapToRunDto.showInHomePage,
unitUuid: spaceUuid ? spaceUuid : addSceneTapToRunDto.spaceUuid, spaceUuid: spaceUuid ? spaceUuid : addSceneTapToRunDto.spaceUuid,
}); });
} }
return { return {
@ -124,7 +124,7 @@ export class SceneService {
throw err; // Re-throw BadRequestException throw err; // Re-throw BadRequestException
} else { } else {
throw new HttpException( throw new HttpException(
err.message || 'Scene not found', err.message || `Scene not found`,
err.status || HttpStatus.NOT_FOUND, err.status || HttpStatus.NOT_FOUND,
); );
} }
@ -160,13 +160,14 @@ export class SceneService {
} }
} }
} }
async getTapToRunSceneByUnit(unitUuid: string, inHomePage: GetSceneDto) {
async getTapToRunSceneByUnit(spaceUuid: string, inHomePage: GetSceneDto) {
try { try {
const showInHomePage = inHomePage?.showInHomePage; const showInHomePage = inHomePage?.showInHomePage;
const scenesData = await this.sceneRepository.find({ const scenesData = await this.sceneRepository.find({
where: { where: {
unitUuid, spaceUuid,
...(showInHomePage ? { showInHomePage } : {}), ...(showInHomePage ? { showInHomePage } : {}),
}, },
}); });
@ -180,6 +181,7 @@ export class SceneService {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const { actions, ...rest } = sceneData; const { actions, ...rest } = sceneData;
return { return {
uuid: scene.uuid,
...rest, ...rest,
}; };
}), }),
@ -197,6 +199,7 @@ export class SceneService {
} }
} }
} }
async deleteTapToRunScene(param: DeleteSceneParamDto, spaceTuyaId = null) { async deleteTapToRunScene(param: DeleteSceneParamDto, spaceTuyaId = null) {
const { spaceUuid, sceneUuid } = param; const { spaceUuid, sceneUuid } = param;
try { try {
@ -317,7 +320,10 @@ export class SceneService {
if (err instanceof BadRequestException) { if (err instanceof BadRequestException) {
throw err; // Re-throw BadRequestException throw err; // Re-throw BadRequestException
} else { } else {
throw new HttpException('Scene not found', HttpStatus.NOT_FOUND); throw new HttpException(
`Scene not found for ${sceneId}`,
HttpStatus.NOT_FOUND,
);
} }
} }
} }
@ -375,7 +381,7 @@ export class SceneService {
const newTapToRunScene = await this.addTapToRunScene( const newTapToRunScene = await this.addTapToRunScene(
addSceneTapToRunDto, addSceneTapToRunDto,
spaceTuyaId.spaceId, spaceTuyaId.spaceId,
scene.unitUuid, scene.spaceUuid,
); );
const param: DeleteSceneParamDto = { const param: DeleteSceneParamDto = {
@ -394,7 +400,7 @@ export class SceneService {
sceneIcon: { sceneIcon: {
uuid: addSceneTapToRunDto.iconUuid, uuid: addSceneTapToRunDto.iconUuid,
}, },
unitUuid: scene.unitUuid, spaceUuid: scene.spaceUuid,
}, },
); );
return newTapToRunScene; return newTapToRunScene;
@ -404,7 +410,7 @@ export class SceneService {
throw err; // Re-throw BadRequestException throw err; // Re-throw BadRequestException
} else { } else {
throw new HttpException( throw new HttpException(
err.message || 'Scene not found', err.message || `Scene not found for id ${sceneUuid}`,
err.status || HttpStatus.NOT_FOUND, err.status || HttpStatus.NOT_FOUND,
); );
} }