|
@@ -102,7 +102,7 @@ export class DevicesService {
|
|
|
// ── Heartbeat ──────────────────────────────────────────────
|
|
// ── Heartbeat ──────────────────────────────────────────────
|
|
|
|
|
|
|
|
async createHeartbeat(dto: HeartbeatDto, apiKey: string) {
|
|
async createHeartbeat(dto: HeartbeatDto, apiKey: string) {
|
|
|
- const device = await this.repo.findDeviceById(dto.deviceId)
|
|
|
|
|
|
|
+ const device = (await this.repo.findDeviceById(dto.deviceId)) ?? await this.repo.findBySerialNo(dto.deviceId)
|
|
|
if (!device) throw new NotFoundException(`Device ${dto.deviceId} not found`)
|
|
if (!device) throw new NotFoundException(`Device ${dto.deviceId} not found`)
|
|
|
|
|
|
|
|
const validKey = await this.repo.verifyApiKey(device.apiKeyHash, apiKey)
|
|
const validKey = await this.repo.verifyApiKey(device.apiKeyHash, apiKey)
|
|
@@ -115,7 +115,7 @@ export class DevicesService {
|
|
|
|
|
|
|
|
await Promise.all([
|
|
await Promise.all([
|
|
|
this.repo.insertHeartbeat({
|
|
this.repo.insertHeartbeat({
|
|
|
- deviceId: dto.deviceId,
|
|
|
|
|
|
|
+ deviceId: device.id,
|
|
|
tempC: dto.tempC ?? null,
|
|
tempC: dto.tempC ?? null,
|
|
|
batteryPct: dto.batteryPct ?? null,
|
|
batteryPct: dto.batteryPct ?? null,
|
|
|
storageFreeGb: dto.storageFreeGb,
|
|
storageFreeGb: dto.storageFreeGb,
|
|
@@ -123,10 +123,10 @@ export class DevicesService {
|
|
|
lastCaptureAt: dto.lastCaptureAt ?? null,
|
|
lastCaptureAt: dto.lastCaptureAt ?? null,
|
|
|
networkStatus: dto.networkStatus ?? 'online',
|
|
networkStatus: dto.networkStatus ?? 'online',
|
|
|
}),
|
|
}),
|
|
|
- this.repo.updateDeviceStatus(dto.deviceId, dto.status, now, dto.firmwareVersion),
|
|
|
|
|
|
|
+ this.repo.updateDeviceStatus(device.id, dto.status, now, dto.firmwareVersion),
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
- const pendingCommands = await this.repo.getPendingCommandCount(dto.deviceId)
|
|
|
|
|
|
|
+ const pendingCommands = await this.repo.getPendingCommandCount(device.id)
|
|
|
|
|
|
|
|
if (device.projectId && device.orgId) {
|
|
if (device.projectId && device.orgId) {
|
|
|
this.realtime.emitDeviceHeartbeat(
|
|
this.realtime.emitDeviceHeartbeat(
|