feat: integration with API Vega Cloud

This commit is contained in:
2025-10-14 11:16:23 +07:00
parent 8b24695a75
commit 1d341c3a7c
23 changed files with 468 additions and 431 deletions
+43
View File
@@ -0,0 +1,43 @@
import { httpRequest } from '~/helpers/http/axios'
import logger from '~/plugins/logger'
export async function queryDeviceStatus(topic: string): Promise<{
floor: string
unit: string
device: string
room: string
devType: string
code: string
tower: string
payload: string
} | null> {
try {
const response = await httpRequest({
method: 'GET',
url: '/state-reply',
body: { topic },
})
if ((response.data as Record<string, unknown>) && (response.data as Record<string, unknown>).data) {
const thirdPartyData = (response.data as Record<string, unknown>).data as Record<string, unknown>
logger.info({ msg: 'Device status queried successfully', topic, status: response.status })
return {
floor: thirdPartyData.floor as string,
unit: thirdPartyData.unit as string,
device: thirdPartyData.device as string,
room: thirdPartyData.room as string,
devType: thirdPartyData.devType as string,
code: thirdPartyData.code as string,
tower: thirdPartyData.tower as string,
payload: thirdPartyData.payload as string,
}
} else {
logger.info({ msg: 'Device status not found', topic, status: response.status })
return null
}
} catch (error) {
logger.error({ msg: 'Failed to query device status', topic, error: (error as Error).message })
throw new Error('third_party_query_failed')
}
}