diff --git a/src/group/controllers/group.controller.ts b/src/group/controllers/group.controller.ts index 1db7a11..7b5b12d 100644 --- a/src/group/controllers/group.controller.ts +++ b/src/group/controllers/group.controller.ts @@ -8,6 +8,7 @@ import { Query, Param, Put, + Delete, } from '@nestjs/common'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard'; @@ -70,4 +71,15 @@ export class GroupController { throw new Error(err); } } + + @ApiBearerAuth() + @UseGuards(JwtAuthGuard) + @Delete(':groupId') + async deleteGroup(@Param('groupId') groupId: number) { + try { + return await this.groupService.deleteGroup(groupId); + } catch (err) { + throw new Error(err); + } + } } diff --git a/src/group/interfaces/get.group.interface.ts b/src/group/interfaces/get.group.interface.ts index 69c5050..94dec62 100644 --- a/src/group/interfaces/get.group.interface.ts +++ b/src/group/interfaces/get.group.interface.ts @@ -24,9 +24,3 @@ export class controlGroupInterface { result: boolean; msg: string; } - -export class renameGroupInterface { - success: boolean; - result: boolean; - msg: string; -} diff --git a/src/group/services/group.service.ts b/src/group/services/group.service.ts index c534d39..48cadeb 100644 --- a/src/group/services/group.service.ts +++ b/src/group/services/group.service.ts @@ -7,7 +7,6 @@ import { GetRoomDetailsInterface, addGroupInterface, controlGroupInterface, - renameGroupInterface, } from '../interfaces/get.group.interface'; import { GetGroupDto } from '../dtos/get.group.dto'; import { ControlGroupDto } from '../dtos/control.group.dto'; @@ -165,7 +164,11 @@ export class GroupService { const response = await this.renameGroupTuya(renameGroupDto); if (response.success) { - return response; + return { + success: response.success, + result: response.result, + msg: response.msg, + }; } else { throw new HttpException( response.msg || 'Unknown error', @@ -175,7 +178,7 @@ export class GroupService { } async renameGroupTuya( renameGroupDto: RenameGroupDto, - ): Promise { + ): Promise { try { const path = `/v2.0/cloud/thing/group/${renameGroupDto.groupId}/${renameGroupDto.groupName}`; const response = await this.tuya.request({ @@ -183,10 +186,43 @@ export class GroupService { path, }); - return response as renameGroupInterface; + return response as controlGroupInterface; } catch (error) { throw new HttpException( - 'Error control group', + 'Error rename group', + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + + async deleteGroup(groupId: number) { + const response = await this.deleteGroupTuya(groupId); + + if (response.success) { + return { + success: response.success, + result: response.result, + msg: response.msg, + }; + } else { + throw new HttpException( + response.msg || 'Unknown error', + HttpStatus.BAD_REQUEST, + ); + } + } + async deleteGroupTuya(groupId: number): Promise { + try { + const path = `/v2.0/cloud/thing/group/${groupId}`; + const response = await this.tuya.request({ + method: 'DELETE', + path, + }); + + return response as controlGroupInterface; + } catch (error) { + throw new HttpException( + 'Error delete group', HttpStatus.INTERNAL_SERVER_ERROR, ); }