chore: change validation unitNumber to alphabet
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { dataMapping } from '~/helpers/utils'
|
||||
import { DeviceCommandBody } from '../schema'
|
||||
import { sendCommandToThirdParty } from './command'
|
||||
import { alphabetToNumberString } from '~/helpers/alphabet_conversion'
|
||||
|
||||
export default abstract class CommandService {
|
||||
static async sendCommand(body: DeviceCommandBody): Promise<{
|
||||
@@ -8,7 +9,8 @@ export default abstract class CommandService {
|
||||
message: string
|
||||
receivedAt: string
|
||||
}> {
|
||||
const topicData = `${body.merchantName}/${body.floorName}_${body.unitNumber}-${body.deviceName}-${body.roomName}-${body.deviceType}-${body.commandType}-${body.towerNumber}`
|
||||
const unitNumber = alphabetToNumberString(body.unitNumber)
|
||||
const topicData = `${body.merchantName}/${body.floorName}_${unitNumber}-${body.deviceName}-${body.roomName}-${body.deviceType}-${body.commandType}-${body.towerNumber}`
|
||||
const cmd = dataMapping.find((device) => device.deviceName == body.deviceName)
|
||||
const request = await sendCommandToThirdParty(topicData, `${cmd?.command}${body.payload.action}`)
|
||||
if (request.status !== 200) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { alphabetToNumberString } from '~/helpers/alphabet_conversion'
|
||||
import { sendQueryToThirdParty } from '../commands/command'
|
||||
import { DeviceQueryParams } from '../schema'
|
||||
|
||||
@@ -17,8 +18,8 @@ export default abstract class QueryService {
|
||||
} | null
|
||||
}> {
|
||||
// TODO: Check nonce for replay attack when DB is implemented
|
||||
|
||||
const topic = `${query.merchantName}/${query.floorName}_${query.unitNumber}-${query.deviceName}-${query.roomName}-${query.deviceType}-S-${query.towerNumber}`
|
||||
const unitNumber = alphabetToNumberString(query.unitNumber)
|
||||
const topic = `${query.merchantName}/${query.floorName}_${unitNumber}-${query.deviceName}-${query.roomName}-${query.deviceType}-S-${query.towerNumber}`
|
||||
|
||||
const request = await sendQueryToThirdParty(topic)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { z } from 'zod'
|
||||
export const deviceCommandBody = z.object({
|
||||
merchantName: z.string(),
|
||||
floorName: z.string(),
|
||||
unitNumber: z.string(),
|
||||
unitNumber: z.string().regex(/^[A-Z]+$/, 'unitNumber must contain only uppercase alphabet characters'),
|
||||
deviceName: z.string(),
|
||||
roomName: z.string(),
|
||||
deviceType: z.string(),
|
||||
@@ -20,7 +20,7 @@ export type DeviceCommandBody = z.infer<typeof deviceCommandBody>
|
||||
export const deviceQueryParams = z.object({
|
||||
merchantName: z.string(),
|
||||
floorName: z.string(),
|
||||
unitNumber: z.string(),
|
||||
unitNumber: z.string().regex(/^[A-Z]+$/, 'unitNumber must contain only uppercase alphabet characters'),
|
||||
deviceName: z.string(),
|
||||
roomName: z.string(),
|
||||
deviceType: z.string(),
|
||||
|
||||
Reference in New Issue
Block a user