diff options
Diffstat (limited to 'src/internal-server/app/Middleware')
-rw-r--r-- | src/internal-server/app/Middleware/ConvertEmptyStringsToNull.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/internal-server/app/Middleware/ConvertEmptyStringsToNull.js b/src/internal-server/app/Middleware/ConvertEmptyStringsToNull.js new file mode 100644 index 000000000..87f1f6c25 --- /dev/null +++ b/src/internal-server/app/Middleware/ConvertEmptyStringsToNull.js | |||
@@ -0,0 +1,15 @@ | |||
1 | class ConvertEmptyStringsToNull { | ||
2 | async handle({ request }, next) { | ||
3 | if (Object.keys(request.body).length) { | ||
4 | request.body = Object.assign( | ||
5 | ...Object.keys(request.body).map(key => ({ | ||
6 | [key]: request.body[key] !== '' ? request.body[key] : null, | ||
7 | })), | ||
8 | ); | ||
9 | } | ||
10 | |||
11 | await next(); | ||
12 | } | ||
13 | } | ||
14 | |||
15 | module.exports = ConvertEmptyStringsToNull; | ||