mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 07:07:21 +00:00
add tag uuid to add device API (#450)
This commit is contained in:
@ -18,6 +18,14 @@ export class AddDeviceDto {
|
||||
@IsNotEmpty()
|
||||
public spaceUuid: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'tagUuid',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public tagUuid: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'deviceName',
|
||||
required: true,
|
||||
|
@ -162,10 +162,24 @@ export class DeviceService {
|
||||
if (!device.productUuid) {
|
||||
throw new Error('Product UUID is missing for the device.');
|
||||
}
|
||||
const existingConflictingDevice = await this.deviceRepository.exists({
|
||||
where: {
|
||||
spaceDevice: { uuid: addDeviceDto.spaceUuid },
|
||||
productDevice: { uuid: device.productUuid },
|
||||
tag: { uuid: addDeviceDto.tagUuid },
|
||||
},
|
||||
});
|
||||
if (existingConflictingDevice) {
|
||||
throw new HttpException(
|
||||
'Device with the same product type and tag already exists in this space',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
const deviceSaved = await this.deviceRepository.save({
|
||||
deviceTuyaUuid: addDeviceDto.deviceTuyaUuid,
|
||||
productDevice: { uuid: device.productUuid },
|
||||
spaceDevice: { uuid: addDeviceDto.spaceUuid },
|
||||
tag: { uuid: addDeviceDto.tagUuid },
|
||||
name: addDeviceDto.deviceName,
|
||||
});
|
||||
if (deviceSaved.uuid) {
|
||||
|
Reference in New Issue
Block a user