From a4fdc4fb772f730aed08275cdda3495d857806ce Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Mon, 23 Oct 2023 10:51:22 -0400 Subject: [PATCH] fix #493: remove nulls from cerateCall payload in order not to trip up validation --- lib/http-routes/api/create-call.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/http-routes/api/create-call.js b/lib/http-routes/api/create-call.js index 33fd08a8b..af1440fc8 100644 --- a/lib/http-routes/api/create-call.js +++ b/lib/http-routes/api/create-call.js @@ -15,14 +15,22 @@ const dbUtils = require('../../utils/db-utils'); const { mergeSdpMedia, extractSdpMedia } = require('../../utils/sdp-utils'); const { createCallSchema } = require('../schemas/create-call'); +const removeNullProperties = (obj) => (Object.keys(obj).forEach((key) => obj[key] === null && delete obj[key]), obj); +const removeNulls = (req, res, next) => { + req.body = removeNullProperties(req.body); + next(); +}; + router.post('/', + removeNulls, createCallSchema, async(req, res) => { + const {logger} = req.app.locals; const errors = validationResult(req); if (!errors.isEmpty()) { + logger.info({errors: errors.array()}, 'POST /Calls: validation errors'); return res.status(400).json({ errors: errors.array() }); } - const {logger} = req.app.locals; const accountSid = req.body.account_sid; const {srf} = require('../../..');