Skip to content

Instantly share code, notes, and snippets.

@k1r0s
Created August 26, 2018 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k1r0s/091571829607c3ef4e6cbcd9a38c9bfc to your computer and use it in GitHub Desktop.
Save k1r0s/091571829607c3ef4e6cbcd9a38c9bfc to your computer and use it in GitHub Desktop.
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