From e325d6d2b1b749d0d0979dcb52fe2247b50c9a0c Mon Sep 17 00:00:00 2001 From: Cesar <26280794+csrapr@users.noreply.github.com> Date: Wed, 2 Dec 2020 19:02:57 +0000 Subject: [PATCH] Feat: validate axios request and enable commissions switch --- lib/coinatmradar/coinatmradar.js | 58 ++++++++++++++++++- .../OperatorInfo/CoinATMRadar/CoinATMRadar.js | 4 +- package-lock.json | 42 ++++++++++++++ package.json | 3 +- 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/lib/coinatmradar/coinatmradar.js b/lib/coinatmradar/coinatmradar.js index 79465bf5..cddc608b 100644 --- a/lib/coinatmradar/coinatmradar.js +++ b/lib/coinatmradar/coinatmradar.js @@ -1,6 +1,7 @@ const axios = require('axios') const _ = require('lodash/fp') const hkdf = require('futoin-hkdf') +const yup = require("yup") const pify = require('pify') const fs = pify(require('fs')) @@ -114,6 +115,60 @@ function getMachines (rates, settings) { .then(_.map(_.partial(mapMachine, [rates, settings]))) } +function validateData (data) { + const schema = yup.object().shape({ + operatorId: yup.string().required('operatorId not provided'), + operator: yup.object().shape({ + name: yup.string().nullable(), + phone: yup.string().nullable(), + email: yup.string().email().nullable() + }), + timestamp: yup.string().required('timestamp not provided'), + machines: yup.array().of(yup.object().shape({ + machineId: yup.string().required('machineId not provided'), + address: yup.object().required('address object not provided').shape({ + streetAddress: yup.string().nullable(), + city: yup.string().nullable(), + region: yup.string().nullable(), + postalCode: yup.string().nullable(), + country: yup.string().nullable() + }), + location: yup.object().required('location object not provided').shape({ + name: yup.string().nullable(), + url: yup.string().nullable(), + phone: yup.string().nullable() + }), + status: yup.string().required('status not provided').oneOf(['online', 'offline']), + lastOnline: yup.string().required('date in isostring format not provided'), + cashIn: yup.boolean().required('cashIn boolean not defined'), + cashOut: yup.boolean().required('cashOut boolean not defined'), + manufacturer: yup.string().required('manufacturer not provided'), + cashInTxLimit: yup.number().nullable(), + cashOutTxLimit: yup.number().nullable(), + cashInDailyLimit: yup.number().nullable(), + cashOutDailyLimit: yup.number().nullable(), + fiatCurrency: yup.string().required('fiatCurrency not provided'), + identification: yup.object().shape({ + isPhone: yup.boolean().required('isPhone boolean not defined'), + isPalmVein: yup.boolean().required('isPalmVein boolean not defined'), + isPhoto: yup.boolean().required('isPhoto boolean not defined'), + isIdDocScan: yup.boolean().required('isIdDocScan boolean not defined'), + isFingerprint: yup.boolean().required('isFingerprint boolean not defined') + }), + coins: yup.array().of(yup.object().shape({ + cryptoCode: yup.string().required('cryptoCode not provided'), + cashInFee: yup.number().nullable(), + cashOutFee: yup.number().nullable(), + cashInFixedFee: yup.number().nullable(), + cashInRate: yup.number().nullable(), + cashOutRate: yup.number().nullable(), + })) + })) + }) + + return schema.validate(data) +} + function sendRadar (data) { const url = _.get(['coinAtmRadar', 'url'], options) @@ -130,7 +185,8 @@ function sendRadar (data) { } console.log('%j', data) - return axios(config) + return validateData(data) + .then(() => axios(config)) .then(r => console.log(r.status)) } diff --git a/new-lamassu-admin/src/pages/OperatorInfo/CoinATMRadar/CoinATMRadar.js b/new-lamassu-admin/src/pages/OperatorInfo/CoinATMRadar/CoinATMRadar.js index e4628803..4bdf6d4e 100644 --- a/new-lamassu-admin/src/pages/OperatorInfo/CoinATMRadar/CoinATMRadar.js +++ b/new-lamassu-admin/src/pages/OperatorInfo/CoinATMRadar/CoinATMRadar.js @@ -86,12 +86,12 @@ const CoinATMRadar = memo(() => { label={coinAtmRadarConfig.active ? 'Yes' : 'No'} />

{'Machine info'}

- {/* save({ commissions: value })} - /> */} + />