Official Plugins (Kuzzle v2.x)
Device Manager v0.x
2

validate #

Validate the payload format before processing.

This method must throw an error if the payload is not valid.

validate (payload: JSONObject, request: KuzzleRequest): Promise<void> | never

ArgumentsTypeDescription
payload
JSONObject
Raw payload received in the API action body
request
KuzzleRequest
Original request

Returns #

Returns a promise resolving if the payload is valid.

Usage #

Considering the following payload:

{
  deviceEUI: '12345',
  register55: 23.3,
  batteryLevel: 0.8,
}

The following validate method could be implemented:

import { JSONObject, KuzzleRequest, BadRequestError } from 'kuzzle';
import { Decoder } from 'kuzzle-plugin-device-manager';

class KarakoyDecoder extends Decoder {
  // [...]
  async validate (payload: JSONObject, request: KuzzleRequest): Promise<void> | never {
    if (typeof payload.deviceEUI !== 'string') {
      throw new BadRequestError('Missing "deviceEUI" property');
    }
  }
}