You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jeff-downloader/app/Middleware/ConvertEmptyStringsToNull.js

18 lines
379 B
JavaScript

'use strict'
class ConvertEmptyStringsToNull {
async handle ({ request }, next) {
if (Object.keys(request.body).length) {
request.body = Object.assign(
...Object.keys(request.body).map(key => ({
[key]: request.body[key] !== '' ? request.body[key] : null
}))
)
}
await next()
}
}
module.exports = ConvertEmptyStringsToNull