add tag uuid to add device API (#450)

This commit is contained in:
ZaydSkaff
2025-07-03 16:23:42 +03:00
committed by GitHub
parent 60bc03cf79
commit 807c5b7dd3
2 changed files with 22 additions and 0 deletions

View File

@ -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,

View File

@ -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) {