Skip to content

Instantly share code, notes, and snippets.

@madiodio
Last active November 26, 2018 10:00
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 madiodio/d5066d9f79fae61270cb13b5039a6e46 to your computer and use it in GitHub Desktop.
Save madiodio/d5066d9f79fae61270cb13b5039a6e46 to your computer and use it in GitHub Desktop.
import Express from "express";
import { createMerchant } from "paths";
const app = Express();
app.post("/createMerchant", createMerchant);
import { validateReqParams, toSnakeCase } from "utils";
import { createMerchant as createTookanMerchant } from "utils/tookan";
export const createMerchant = async (req, res) => {
const params = req.body;
if (validateReqParams(params, "createMerchant")) {
try {
const paramsToSend = toSnakeCase(params);
const createdMerchant = await createTookanMerchant(paramsToSend);
res.status(200).json(createdMerchant);
} catch (error) {
console.log(error);
res.status(100).json({
code: "502 Bad Gateway",
message: "Something unexpected happened, we're already on it :)"
});
}
} else {
res.status(400).json({
code: "400 Bad request",
message: "There is something wrong. You're missing an argument or parameter."
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment