finished 4scene configration endpoints

This commit is contained in:
faris Aljohari
2024-11-16 23:05:06 -06:00
parent 4bb598d8b0
commit eb916b79b4
25 changed files with 429 additions and 15 deletions

View File

@ -30,6 +30,7 @@ import {
} from '@app/common/constants/automation.enum';
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
import { ConvertedAction } from '@app/common/integrations/tuya/interfaces';
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
@Injectable()
export class AutomationService {
@ -39,6 +40,7 @@ export class AutomationService {
private readonly spaceRepository: SpaceRepository,
private readonly deviceService: DeviceService,
private readonly tuyaService: TuyaService,
private readonly sceneDeviceRepository: SceneDeviceRepository,
) {
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
const secretKey = this.configService.get<string>('auth-config.SECRET_KEY');
@ -304,6 +306,16 @@ export class AutomationService {
HttpStatus.BAD_REQUEST,
);
}
const existingSceneDevice = await this.sceneDeviceRepository.findOne({
where: { automationTuyaUuid: automationUuid },
});
if (existingSceneDevice) {
await this.sceneDeviceRepository.delete({
automationTuyaUuid: automationUuid,
});
}
const response = this.tuyaService.deleteAutomation(
automation.spaceId,
automationUuid,
@ -323,6 +335,15 @@ export class AutomationService {
async delete(tuyaSpaceId: string, automationUuid: string) {
try {
const existingSceneDevice = await this.sceneDeviceRepository.findOne({
where: { automationTuyaUuid: automationUuid },
});
if (existingSceneDevice) {
await this.sceneDeviceRepository.delete({
automationTuyaUuid: automationUuid,
});
}
const response = await this.tuyaService.deleteAutomation(
tuyaSpaceId,
automationUuid,