Update device status logs to handle multiple properties

This commit is contained in:
faris Aljohari
2025-01-21 00:02:17 -06:00
parent 6dba022350
commit 42c3f3c150

View File

@ -187,19 +187,19 @@ export class DeviceStatusFirebaseService {
code,
value,
}));
const newLog = this.deviceStatusLogRepository.create({
deviceId: addDeviceStatusDto.deviceUuid,
deviceTuyaId: addDeviceStatusDto.deviceTuyaUuid,
productId: addDeviceStatusDto.log.productId,
log: addDeviceStatusDto.log,
code: existingData.status[0].code,
value: existingData.status[0].value,
eventId: addDeviceStatusDto.log.dataId,
eventTime: new Date(
addDeviceStatusDto.log.properties[0].time,
).toISOString(),
const newLogs = addDeviceStatusDto.log.properties.map((property) => {
return this.deviceStatusLogRepository.create({
deviceId: addDeviceStatusDto.deviceUuid,
deviceTuyaId: addDeviceStatusDto.deviceTuyaUuid,
productId: addDeviceStatusDto.log.productId,
log: addDeviceStatusDto.log,
code: property.code,
value: property.value,
eventId: addDeviceStatusDto.log.dataId,
eventTime: new Date(property.time).toISOString(),
});
});
await this.deviceStatusLogRepository.save(newLog);
await this.deviceStatusLogRepository.save(newLogs);
// Save the updated data to Firebase
await set(dataRef, existingData);