mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 20:24:54 +00:00
resolve conflicts
This commit is contained in:
@ -6,7 +6,6 @@ import {
|
||||
Post,
|
||||
Query,
|
||||
Param,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
UseGuards,
|
||||
Req,
|
||||
@ -44,34 +43,20 @@ export class DeviceController {
|
||||
@UseGuards(SuperAdminRoleGuard, CheckDeviceGuard)
|
||||
@Post()
|
||||
async addDeviceUser(@Body() addDeviceDto: AddDeviceDto) {
|
||||
try {
|
||||
const device = await this.deviceService.addDeviceUser(addDeviceDto);
|
||||
const device = await this.deviceService.addDeviceUser(addDeviceDto);
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'device added successfully',
|
||||
data: device,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'device added successfully',
|
||||
data: device,
|
||||
};
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('user/:userUuid')
|
||||
async getDevicesByUser(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesByUser(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.getDevicesByUser(userUuid);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckRoomGuard)
|
||||
@ -80,31 +65,17 @@ export class DeviceController {
|
||||
@Query() getDeviceByRoomUuidDto: GetDeviceByRoomUuidDto,
|
||||
@Req() req: any,
|
||||
) {
|
||||
try {
|
||||
const userUuid = req.user.uuid;
|
||||
return await this.deviceService.getDevicesByRoomId(
|
||||
getDeviceByRoomUuidDto,
|
||||
userUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
const userUuid = req.user.uuid;
|
||||
return await this.deviceService.getDevicesByRoomId(
|
||||
getDeviceByRoomUuidDto,
|
||||
userUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('unit/:unitUuid')
|
||||
async getDevicesByUnitId(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesByUnitId(unitUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.getDevicesByUnitId(unitUuid);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckRoomGuard)
|
||||
@ -112,23 +83,16 @@ export class DeviceController {
|
||||
async updateDeviceInRoom(
|
||||
@Body() updateDeviceInRoomDto: UpdateDeviceInRoomDto,
|
||||
) {
|
||||
try {
|
||||
const device = await this.deviceService.updateDeviceInRoom(
|
||||
updateDeviceInRoomDto,
|
||||
);
|
||||
const device = await this.deviceService.updateDeviceInRoom(
|
||||
updateDeviceInRoomDto,
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'device updated in room successfully',
|
||||
data: device,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'device updated in room successfully',
|
||||
data: device,
|
||||
};
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -138,18 +102,11 @@ export class DeviceController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Req() req: any,
|
||||
) {
|
||||
try {
|
||||
const userUuid = req.user.uuid;
|
||||
return await this.deviceService.getDeviceDetailsByDeviceId(
|
||||
deviceUuid,
|
||||
userUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
const userUuid = req.user.uuid;
|
||||
return await this.deviceService.getDeviceDetailsByDeviceId(
|
||||
deviceUuid,
|
||||
userUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckUserHavePermission)
|
||||
@ -157,29 +114,13 @@ export class DeviceController {
|
||||
async getDeviceInstructionByDeviceId(
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.getDeviceInstructionByDeviceId(
|
||||
deviceUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.getDeviceInstructionByDeviceId(deviceUuid);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckUserHavePermission)
|
||||
@Get(':deviceUuid/functions/status')
|
||||
async getDevicesInstructionStatus(@Param('deviceUuid') deviceUuid: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesInstructionStatus(deviceUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.getDevicesInstructionStatus(deviceUuid);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -189,17 +130,7 @@ export class DeviceController {
|
||||
@Body() controlDeviceDto: ControlDeviceDto,
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.controlDevice(
|
||||
controlDeviceDto,
|
||||
deviceUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.controlDevice(controlDeviceDto, deviceUuid);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -208,43 +139,22 @@ export class DeviceController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Param('firmwareVersion') firmwareVersion: number,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.updateDeviceFirmware(
|
||||
deviceUuid,
|
||||
firmwareVersion,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.updateDeviceFirmware(
|
||||
deviceUuid,
|
||||
firmwareVersion,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('gateway/:gatewayUuid/devices')
|
||||
async getDevicesInGateway(@Param('gatewayUuid') gatewayUuid: string) {
|
||||
try {
|
||||
return await this.deviceService.getDevicesInGateway(gatewayUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.getDevicesInGateway(gatewayUuid);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
async getAllDevices() {
|
||||
try {
|
||||
return await this.deviceService.getAllDevices();
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.getAllDevices();
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -253,14 +163,7 @@ export class DeviceController {
|
||||
@Param('deviceUuid') deviceUuid: string,
|
||||
@Query() query: GetDeviceLogsDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.getDeviceLogs(deviceUuid, query);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.getDeviceLogs(deviceUuid, query);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -268,16 +171,7 @@ export class DeviceController {
|
||||
async batchControlDevices(
|
||||
@Body() batchControlDevicesDto: BatchControlDevicesDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.batchControlDevices(
|
||||
batchControlDevicesDto,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.batchControlDevices(batchControlDevicesDto);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -285,14 +179,7 @@ export class DeviceController {
|
||||
async batchStatusDevices(
|
||||
@Query() batchStatusDevicesDto: BatchStatusDevicesDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.batchStatusDevices(batchStatusDevicesDto);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.batchStatusDevices(batchStatusDevicesDto);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ -300,15 +187,8 @@ export class DeviceController {
|
||||
async batchFactoryResetDevices(
|
||||
@Body() batchFactoryResetDevicesDto: BatchFactoryResetDevicesDto,
|
||||
) {
|
||||
try {
|
||||
return await this.deviceService.batchFactoryResetDevices(
|
||||
batchFactoryResetDevicesDto,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
return await this.deviceService.batchFactoryResetDevices(
|
||||
batchFactoryResetDevicesDto,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,6 +64,7 @@ export class DeviceService {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
},
|
||||
...(withProductDevice && { relations: ['productDevice'] }),
|
||||
});
|
||||
@ -72,6 +73,7 @@ export class DeviceService {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
deviceTuyaUuid,
|
||||
isActive: true,
|
||||
},
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
@ -128,6 +130,7 @@ export class DeviceService {
|
||||
const devices = await this.deviceRepository.find({
|
||||
where: {
|
||||
user: { uuid: userUuid },
|
||||
isActive: true,
|
||||
permission: {
|
||||
userUuid,
|
||||
permissionType: {
|
||||
@ -174,6 +177,7 @@ export class DeviceService {
|
||||
const devices = await this.deviceRepository.find({
|
||||
where: {
|
||||
spaceDevice: { uuid: getDeviceByRoomUuidDto.roomUuid },
|
||||
isActive: true,
|
||||
permission: {
|
||||
userUuid,
|
||||
permissionType: {
|
||||
@ -223,6 +227,7 @@ export class DeviceService {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: updateDeviceInRoomDto.deviceUuid,
|
||||
isActive: true,
|
||||
},
|
||||
relations: ['spaceDevice', 'spaceDevice.parent'],
|
||||
});
|
||||
@ -409,7 +414,7 @@ export class DeviceService {
|
||||
}
|
||||
async checkAllDevicesHaveSameProductUuid(deviceUuids: string[]) {
|
||||
const firstDevice = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuids[0] },
|
||||
where: { uuid: deviceUuids[0], isActive: true },
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
|
||||
@ -421,7 +426,7 @@ export class DeviceService {
|
||||
|
||||
for (let i = 1; i < deviceUuids.length; i++) {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: { uuid: deviceUuids[i] },
|
||||
where: { uuid: deviceUuids[i], isActive: true },
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
|
||||
@ -465,6 +470,11 @@ export class DeviceService {
|
||||
if (operationResult.success) {
|
||||
// Add to success results if operationResult.success is true
|
||||
successResults.push({ deviceUuid, result: operationResult });
|
||||
// Update isActive to false in the repository for the successfully reset device
|
||||
await this.deviceRepository.update(
|
||||
{ uuid: deviceUuid },
|
||||
{ isActive: false },
|
||||
);
|
||||
} else {
|
||||
// Add to failed results if operationResult.success is false
|
||||
failedResults.push({ deviceUuid, error: operationResult.msg });
|
||||
@ -645,6 +655,7 @@ export class DeviceService {
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: deviceUuid,
|
||||
isActive: true,
|
||||
permission: {
|
||||
userUuid: userUuid,
|
||||
},
|
||||
@ -669,19 +680,25 @@ export class DeviceService {
|
||||
|
||||
const devices = await Promise.all(
|
||||
response.map(async (device: any) => {
|
||||
const deviceDetails = await this.getDeviceByDeviceTuyaUuid(device.id);
|
||||
if (deviceDetails.deviceTuyaUuid) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { id, ...rest } = device;
|
||||
return {
|
||||
...rest,
|
||||
tuyaUuid: deviceDetails.deviceTuyaUuid,
|
||||
uuid: deviceDetails.uuid,
|
||||
productUuid: deviceDetails.productDevice.uuid,
|
||||
productType: deviceDetails.productDevice.prodType,
|
||||
};
|
||||
try {
|
||||
const deviceDetails = await this.getDeviceByDeviceTuyaUuid(
|
||||
device.id,
|
||||
);
|
||||
if (deviceDetails.deviceTuyaUuid) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { id, ...rest } = device;
|
||||
return {
|
||||
...rest,
|
||||
tuyaUuid: deviceDetails.deviceTuyaUuid,
|
||||
uuid: deviceDetails.uuid,
|
||||
productUuid: deviceDetails.productDevice.uuid,
|
||||
productType: deviceDetails.productDevice.prodType,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
);
|
||||
|
||||
@ -770,6 +787,9 @@ export class DeviceService {
|
||||
parent: {
|
||||
uuid: unitUuid,
|
||||
},
|
||||
devicesSpaceEntity: {
|
||||
isActive: true,
|
||||
},
|
||||
},
|
||||
relations: ['devicesSpaceEntity', 'devicesSpaceEntity.productDevice'],
|
||||
});
|
||||
@ -804,6 +824,7 @@ export class DeviceService {
|
||||
async getAllDevices(): Promise<GetDeviceDetailsInterface[]> {
|
||||
try {
|
||||
const devices = await this.deviceRepository.find({
|
||||
where: { isActive: true },
|
||||
relations: [
|
||||
'spaceDevice.parent',
|
||||
'productDevice',
|
||||
|
||||
Reference in New Issue
Block a user