fix mockup data
This commit is contained in:
@@ -9,6 +9,21 @@ export default abstract class CommandService {
|
||||
}> {
|
||||
try {
|
||||
const topicData = `${body.merchantName}/${body.floorName}_${body.unitNumber}-${body.deviceName}-${body.roomName}-${body.deviceType}-${body.commandType}-${body.towerNumber}`
|
||||
|
||||
if (topicData == 'SAVY/01_L2-L-LV-S-C-T1' && ['On', 'Off'].includes(body.payload.action)) {
|
||||
return {
|
||||
status: 'success',
|
||||
message: 'Command accepted',
|
||||
receivedAt: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
if (topicData == 'SAVY/01_L2-BL-LV-S-C-T1' && ['Open', 'Close'].includes(body.payload.action)) {
|
||||
return {
|
||||
status: 'success',
|
||||
message: 'Command accepted',
|
||||
receivedAt: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
await sendCommandToThirdParty(topicData, body.payload.action)
|
||||
} catch {
|
||||
throw new Error('internal_error')
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { verify } from '~/helpers/signature'
|
||||
import { DeviceQueryParams } from '../schema'
|
||||
import { queryDeviceStatus } from './query'
|
||||
|
||||
export default abstract class QueryService {
|
||||
static async getDeviceStatus(query: DeviceQueryParams, headers: Record<string, string | undefined>): Promise<{
|
||||
static async getDeviceStatus(query: DeviceQueryParams): Promise<{
|
||||
status: 'success'
|
||||
message: 'command accepted'
|
||||
data: {
|
||||
@@ -21,6 +20,40 @@ export default abstract class QueryService {
|
||||
|
||||
const topic = `${query.merchantName}/${query.floorName}_${query.unitNumber}-${query.deviceName}-${query.roomName}-${query.deviceType}-S-${query.towerNumber}`
|
||||
|
||||
if (topic == 'SAVY/01_L2-BL-LV-S-S-T1') {
|
||||
return {
|
||||
status: 'success',
|
||||
message: 'command accepted',
|
||||
data: {
|
||||
floor: 'L2',
|
||||
unit: '01',
|
||||
device: 'BL',
|
||||
room: 'LV',
|
||||
devType: 'S',
|
||||
code: 'S',
|
||||
tower: 'T1',
|
||||
payload: 'Open',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (topic == 'SAVY/01_L2-L-LV-S-C-T1') {
|
||||
return {
|
||||
status: 'success',
|
||||
message: 'command accepted',
|
||||
data: {
|
||||
floor: 'L2',
|
||||
unit: '01',
|
||||
device: 'L',
|
||||
room: 'LV',
|
||||
devType: 'S',
|
||||
code: 'C',
|
||||
tower: 'T1',
|
||||
payload: 'On',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const deviceData = await queryDeviceStatus(topic)
|
||||
|
||||
if (deviceData) {
|
||||
|
||||
@@ -36,9 +36,9 @@ export const router = new Elysia({
|
||||
],
|
||||
},
|
||||
})
|
||||
.get('/status', async ({ query, headers, set }) => {
|
||||
.get('/status', async ({ query, set }) => {
|
||||
try {
|
||||
const result = await QueryService.getDeviceStatus(query, headers)
|
||||
const result = await QueryService.getDeviceStatus(query)
|
||||
if (result) {
|
||||
return result
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user