From 030570f10a3c92336a6ed2f3ac75944a6e671177 Mon Sep 17 00:00:00 2001 From: moepoi Date: Sun, 21 Nov 2021 09:56:58 +0700 Subject: [PATCH] Add transaction API --- routes/api.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/routes/api.js b/routes/api.js index 93f5cac..dddf284 100644 --- a/routes/api.js +++ b/routes/api.js @@ -386,4 +386,52 @@ router.post("/checkout", async (req, res) => { } }); +router.post("/transaction", async (req, res) => { + if (!req.query.key) { + res.status(401); + res.json({ + message: "Unauthorized", + }); + } else { + auth.auth_checker(req.query.key).then((status) => { + if (status) { + const conn = db.connect(); + conn.query( + "SELECT * FROM users WHERE token = ?", + [req.query.key], + async function (error, response, fields) { + if (error) { + res.status(401); + res.json({ + message: "Unauthorized", + }); + } else { + conn.query( + "SELECT * FROM transactions WHERE userId = ?", + [response[0].id], + async function (error, resp, fields) { + if (error) { + res.status(400); + res.json({ + message: "Bad Request", + }); + } else { + res.status(200); + res.json(resp); + } + } + ); + } + } + ); + } else { + res.status(401); + res.json({ + message: "Unauthorized", + }); + } + }); + } +}); + module.exports = router; \ No newline at end of file