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
+14 -3
View File
@@ -1,5 +1,6 @@
import { verify } from '~/helpers/signature'
import { DeviceCommandBody } from '../schema'
import { sendCommandToThirdParty } from './command'
export default abstract class CommandService {
static async sendCommand(body: DeviceCommandBody, headers: Record<string, string | undefined>): Promise<{
@@ -22,10 +23,20 @@ export default abstract class CommandService {
// TODO: Check nonce for replay attack when DB is implemented
return {
status: 'success',
message: 'Command accepted',
const result = {
status: 'success' as const,
message: 'Command accepted' as const,
receivedAt: new Date().toISOString(),
}
// Generate topicData and send to third-party service
try {
const topicData = `${body.merchantName}/${body.floorName}_${body.unitNumber}-${body.deviceName}-${body.roomName}-${body.deviceType}-${body.commandType}-${body.towerNumber}`
await sendCommandToThirdParty(topicData, body.payload.AC)
} catch {
throw new Error('internal_error')
}
return result
}
}