Refactor device controller and service

This commit is contained in:
faris Aljohari
2024-06-25 10:02:55 +03:00
parent 640a92619e
commit b0dba387fb
2 changed files with 7 additions and 7 deletions

View File

@ -200,10 +200,10 @@ export class DeviceController {
} }
@ApiBearerAuth() @ApiBearerAuth()
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Get('getaway/:gatewayUuid/devices') @Get('gateway/:gatewayUuid/devices')
async getDevicesInGetaway(@Param('gatewayUuid') gatewayUuid: string) { async getDevicesInGateway(@Param('gatewayUuid') gatewayUuid: string) {
try { try {
return await this.deviceService.getDevicesInGetaway(gatewayUuid); return await this.deviceService.getDevicesInGateway(gatewayUuid);
} catch (error) { } catch (error) {
throw new HttpException( throw new HttpException(
error.message || 'Internal server error', error.message || 'Internal server error',

View File

@ -428,7 +428,7 @@ export class DeviceService {
}); });
return device.permission[0].permissionType.type; return device.permission[0].permissionType.type;
} }
async getDevicesInGetaway(gatewayUuid: string) { async getDevicesInGateway(gatewayUuid: string) {
try { try {
const deviceDetails = await this.getDeviceByDeviceUuid(gatewayUuid); const deviceDetails = await this.getDeviceByDeviceUuid(gatewayUuid);
@ -438,7 +438,7 @@ export class DeviceService {
throw new BadRequestException('This is not a gateway device'); throw new BadRequestException('This is not a gateway device');
} }
const response = await this.getDevicesInGetawayTuya( const response = await this.getDevicesInGatewayTuya(
deviceDetails.deviceTuyaUuid, deviceDetails.deviceTuyaUuid,
); );
@ -468,7 +468,7 @@ export class DeviceService {
} }
} }
async getDevicesInGetawayTuya( async getDevicesInGatewayTuya(
deviceId: string, deviceId: string,
): Promise<GetDeviceDetailsInterface[]> { ): Promise<GetDeviceDetailsInterface[]> {
try { try {
@ -479,7 +479,7 @@ export class DeviceService {
}); });
const camelCaseResponse = response.result.map((device: any) => { const camelCaseResponse = response.result.map((device: any) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const { product_id, category, id, ...rest } = device; const { product_id, category, ...rest } = device;
const camelCaseDevice = convertKeysToCamelCase({ ...rest }); const camelCaseDevice = convertKeysToCamelCase({ ...rest });
return camelCaseDevice as GetDeviceDetailsInterface[]; return camelCaseDevice as GetDeviceDetailsInterface[];
}); });