fix mockup data
This commit is contained in:
@@ -9,6 +9,21 @@ export default abstract class CommandService {
|
|||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
const topicData = `${body.merchantName}/${body.floorName}_${body.unitNumber}-${body.deviceName}-${body.roomName}-${body.deviceType}-${body.commandType}-${body.towerNumber}`
|
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)
|
await sendCommandToThirdParty(topicData, body.payload.action)
|
||||||
} catch {
|
} catch {
|
||||||
throw new Error('internal_error')
|
throw new Error('internal_error')
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { verify } from '~/helpers/signature'
|
|
||||||
import { DeviceQueryParams } from '../schema'
|
import { DeviceQueryParams } from '../schema'
|
||||||
import { queryDeviceStatus } from './query'
|
import { queryDeviceStatus } from './query'
|
||||||
|
|
||||||
export default abstract class QueryService {
|
export default abstract class QueryService {
|
||||||
static async getDeviceStatus(query: DeviceQueryParams, headers: Record<string, string | undefined>): Promise<{
|
static async getDeviceStatus(query: DeviceQueryParams): Promise<{
|
||||||
status: 'success'
|
status: 'success'
|
||||||
message: 'command accepted'
|
message: 'command accepted'
|
||||||
data: {
|
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}`
|
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)
|
const deviceData = await queryDeviceStatus(topic)
|
||||||
|
|
||||||
if (deviceData) {
|
if (deviceData) {
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ export const router = new Elysia({
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.get('/status', async ({ query, headers, set }) => {
|
.get('/status', async ({ query, set }) => {
|
||||||
try {
|
try {
|
||||||
const result = await QueryService.getDeviceStatus(query, headers)
|
const result = await QueryService.getDeviceStatus(query)
|
||||||
if (result) {
|
if (result) {
|
||||||
return result
|
return result
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user