Skip to content

Commit

Permalink
Update app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sdhani authored Apr 21, 2021
1 parent 3393232 commit c360eb0
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,6 @@ dotenv.config();
}
});

// API Entry
app.get("/", (req, res) => {
res.status(200).send("Welcome to APMA Backend");
});

// Login
app.post("/api/login", (req, res) => {
console.log("req LOGIN BB", req.body);
console.log("req LOGIN BB", req.params);
const emailCheck = `SELECT * FROM ${req.body.type} WHERE email = '${req.body.email}'`;
client.query(emailCheck, (err, emailRes) => {
if (err) res.status(400).send(err);
if (emailRes.rows.length == 0) {
res
.status(400)
.send({ status: 400, message: "Email does not exist" });
} else if (emailRes.rows[0].password !== req.body.password) {
res.status(400).send({ status: 400, message: "Wrong password" });
} else {
res.status(200).send(emailRes.rows[0]);
}
});
});

// LANDOWNER ENDPOINTS
app.post("/api/landowner", (req, res) => {
const emailCheck = `SELECT * FROM LANDOWNER WHERE email = '${req.body.email}'`;
client.query(emailCheck, (err, emailRes) => {
if (err) res.status(400).send(err);
if (emailRes.rows.length !== 0) {
res
.status(400)
.send({ status: 400, message: "Email already in use" });
} else {
const insertQuery = `insert into LANDOWNER (first_name, last_name, email, password) values ('${req.body.first_name}', '${req.body.last_name}', '${req.body.email}', '${req.body.password}')`;
client.query(insertQuery, (err, queryRes) => {
if (err) res.status(400).send(err);
res.status(200).send({ status: 200, message: "Landowner added" });
});
}
});
});

// Launch Server
app.listen(port, () => {
console.log(`📡 Server up! 📡 Listening on http://localhost:${port}`);
Expand Down

0 comments on commit c360eb0

Please sign in to comment.