mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-14 02:16:19 +01:00
Add transaction API
This commit is contained in:
parent
a49ada9557
commit
030570f10a
1 changed files with 48 additions and 0 deletions
|
@ -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;
|
Loading…
Reference in a new issue