mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-25 07:47:02 +01:00
Add subscribe API
This commit is contained in:
parent
2309e319f5
commit
fc3d5ac31a
1 changed files with 45 additions and 0 deletions
|
@ -448,4 +448,49 @@ router.post("/transaction", async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
router.get("/subscribe", (req, res) => {
|
||||
if (!req.query.email) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
message: "Bad Request",
|
||||
});
|
||||
} else {
|
||||
const conn = db.connect();
|
||||
conn.execute(
|
||||
"SELECT * FROM `subscribe` WHERE `email` = ?",
|
||||
[req.query.email],
|
||||
function (err, results) {
|
||||
if (!results[0]) {
|
||||
let data = {
|
||||
email: req.query.email,
|
||||
type: "email"
|
||||
};
|
||||
conn.query(
|
||||
"INSERT INTO subscribe SET ?",
|
||||
data,
|
||||
function (err, resp) {
|
||||
if (err) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
message: "Bad Request",
|
||||
});
|
||||
} else {
|
||||
res.status(201);
|
||||
res.json({
|
||||
message: "Success",
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.status(200);
|
||||
res.json({
|
||||
message: "Success",
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
Reference in a new issue