generated from shillerben/adonis-fullstack-app
Initial commit
This commit is contained in:
17
app/Middleware/ConvertEmptyStringsToNull.js
Normal file
17
app/Middleware/ConvertEmptyStringsToNull.js
Normal file
@@ -0,0 +1,17 @@
|
||||
'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
|
||||
Reference in New Issue
Block a user