Created
August 26, 2018 15:40
-
-
Save k1r0s/091571829607c3ef4e6cbcd9a38c9bfc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { beforeMethod } from "kaop-ts"; | |
import { | |
BadRequest, | |
ReqTransformBodyAsync | |
} from "@ritley/decorators"; | |
function parseRequestBody(meta) { | |
const [req, res] = meta.args; | |
req.body.then(body => { | |
try { | |
const payload = body.toJSON(); | |
meta.commit(payload); | |
} catch (e) { | |
BadRequest(res, "payload isn't well formed"); | |
} | |
}) | |
} | |
export default beforeMethod( | |
...ReqTransformBodyAsync.advices(), | |
parseRequestBody | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment