Skip to content

Commit

Permalink
Merge pull request #129 from Carifio24/remove-duplicate-handlers
Browse files Browse the repository at this point in the history
Combine handlers for redundant endpoints
  • Loading branch information
Carifio24 authored Sep 12, 2024
2 parents 302afa1 + 1f37023 commit 788a095
Showing 1 changed file with 9 additions and 55 deletions.
64 changes: 9 additions & 55 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ app.listen(PORT, () => {
});

// Educator sign-up
app.post("/educator-sign-up", async (req, res) => {
app.post([
"/educators/create",
"/educator-sign-up", // Old
], async (req, res) => {
const data = req.body;
const valid = (
typeof data.firstName === "string" &&
Expand Down Expand Up @@ -254,13 +257,16 @@ app.post("/educator-sign-up", async (req, res) => {
});

// Student sign-up
app.post("/student-sign-up", async (req, res) => {
app.post([
"/students/create",
"/student-sign-up", // Old
], async (req, res) => {
const data = req.body;
const valid = (
typeof data.username === "string" &&
typeof data.password === "string" &&
((typeof data.institution === "string") || (data.institution == null)) &&
typeof data.email === "string" &&
((typeof data.email === "string") || (data.email == null)) &&
((typeof data.age === "number") || (data.age == null)) &&
((typeof data.gender === "string") || (data.gender == null)) &&
((typeof data.classroom_code === "string") || (data.classroom_code == null))
Expand Down Expand Up @@ -560,58 +566,6 @@ app.post("/classes/join", async (req, res) => {
res.json({ success, message });
});

app.post("/educators/create", async (req, res) => {
const data = req.body;
const valid = (
typeof data.first_name === "string" &&
typeof data.last_name === "string" &&
typeof data.password === "string" &&
((typeof data.institution === "string") || (data.institution == null)) &&
typeof data.email === "string" &&
((typeof data.age === "number") || (data.age == null)) &&
((typeof data.gender === "string") || data.gender == null)
);

let result: SignUpResult;
if (valid) {
result = await signUpEducator(data);
} else {
result = SignUpResult.BadRequest;
res.status(400);
}
res.json({
educator_info: data,
status: result,
success: SignUpResult.success(result)
});
});

app.post("/students/create", async (req, res) => {
const data = req.body;
const valid = (
typeof data.username === "string" &&
typeof data.password === "string" &&
((typeof data.institution === "string") || (data.institution == null)) &&
((typeof data.email === "string") || (data.email == null)) &&
((typeof data.age === "number") || (data.age == null)) &&
((typeof data.gender === "string") || (data.gender == null)) &&
((typeof data.classroom_code === "string") || (data.classroom_code == null))
);

let result: SignUpResult;
if (valid) {
result = await signUpStudent(data);
} else {
result = SignUpResult.BadRequest;
res.status(400);
}
res.json({
student_info: data,
status: result,
success: SignUpResult.success(result)
});
});

/* Classes */
app.post("/classes/create", async (req, res) => {
const data = req.body;
Expand Down

0 comments on commit 788a095

Please sign in to comment.