Skip to content

Commit

Permalink
fix #493: remove nulls from cerateCall payload in order not to trip u…
Browse files Browse the repository at this point in the history
…p validation
  • Loading branch information
davehorton committed Oct 23, 2023
1 parent cf0f4d4 commit a4fdc4f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/http-routes/api/create-call.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('../../..');

Expand Down

0 comments on commit a4fdc4f

Please sign in to comment.