Last active
November 26, 2018 10:00
-
-
Save madiodio/d5066d9f79fae61270cb13b5039a6e46 to your computer and use it in GitHub Desktop.
This file contains 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 Express from "express"; | |
import { createMerchant } from "paths"; | |
const app = Express(); | |
app.post("/createMerchant", createMerchant); |
This file contains 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 { 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