seepur/app/Middleware/ConvertEmptyStringsToNull.js

18 lines
379 B
JavaScript
Raw Normal View History

2020-01-14 01:57:43 +00:00
'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