mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:14:55 +00:00
finished rename group api
This commit is contained in:
@ -7,12 +7,14 @@ import {
|
||||
UseGuards,
|
||||
Query,
|
||||
Param,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||
import { AddGroupDto } from '../dtos/add.group.dto';
|
||||
import { GetGroupDto } from '../dtos/get.group.dto';
|
||||
import { ControlGroupDto } from '../dtos/control.group.dto';
|
||||
import { RenameGroupDto } from '../dtos/rename.group.dto copy';
|
||||
|
||||
@ApiTags('Group Module')
|
||||
@Controller({
|
||||
@ -57,4 +59,15 @@ export class GroupController {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('rename')
|
||||
async renameGroup(@Body() renameGroupDto: RenameGroupDto) {
|
||||
try {
|
||||
return await this.groupService.renameGroup(renameGroupDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsString, IsObject } from 'class-validator';
|
||||
import { IsNotEmpty, IsObject, IsNumberString } from 'class-validator';
|
||||
|
||||
export class ControlGroupDto {
|
||||
@ApiProperty({
|
||||
description: 'groupId',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNumberString()
|
||||
@IsNotEmpty()
|
||||
public groupId: string;
|
||||
|
||||
|
||||
20
src/group/dtos/rename.group.dto copy.ts
Normal file
20
src/group/dtos/rename.group.dto copy.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsString, IsNumberString } from 'class-validator';
|
||||
|
||||
export class RenameGroupDto {
|
||||
@ApiProperty({
|
||||
description: 'groupId',
|
||||
required: true,
|
||||
})
|
||||
@IsNumberString()
|
||||
@IsNotEmpty()
|
||||
public groupId: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'groupName',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public groupName: string;
|
||||
}
|
||||
@ -24,3 +24,9 @@ export class controlGroupInterface {
|
||||
result: boolean;
|
||||
msg: string;
|
||||
}
|
||||
|
||||
export class renameGroupInterface {
|
||||
success: boolean;
|
||||
result: boolean;
|
||||
msg: string;
|
||||
}
|
||||
|
||||
@ -7,9 +7,11 @@ import {
|
||||
GetRoomDetailsInterface,
|
||||
addGroupInterface,
|
||||
controlGroupInterface,
|
||||
renameGroupInterface,
|
||||
} from '../interfaces/get.group.interface';
|
||||
import { GetGroupDto } from '../dtos/get.group.dto';
|
||||
import { ControlGroupDto } from '../dtos/control.group.dto';
|
||||
import { RenameGroupDto } from '../dtos/rename.group.dto copy';
|
||||
|
||||
@Injectable()
|
||||
export class GroupService {
|
||||
@ -158,4 +160,35 @@ export class GroupService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async renameGroup(renameGroupDto: RenameGroupDto) {
|
||||
const response = await this.renameGroupTuya(renameGroupDto);
|
||||
|
||||
if (response.success) {
|
||||
return response;
|
||||
} else {
|
||||
throw new HttpException(
|
||||
response.msg || 'Unknown error',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
}
|
||||
async renameGroupTuya(
|
||||
renameGroupDto: RenameGroupDto,
|
||||
): Promise<renameGroupInterface> {
|
||||
try {
|
||||
const path = `/v2.0/cloud/thing/group/${renameGroupDto.groupId}/${renameGroupDto.groupName}`;
|
||||
const response = await this.tuya.request({
|
||||
method: 'PUT',
|
||||
path,
|
||||
});
|
||||
|
||||
return response as renameGroupInterface;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Error control group',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user