mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
Refactor device controller and service
This commit is contained in:
@ -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',
|
||||||
|
@ -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[];
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user