Skip to content

Commit 154adeb

Browse files
committed
refactor code
1 parent f453aa9 commit 154adeb

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

Sprint 3- middlewares/off-shelf middleware/off shelf.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,16 @@ app.post("/", (req, res) => {
3030
return res.status(400).send("Invalid request body.");
3131
}
3232

33-
if (req.username) {
34-
res.send(
35-
`You are authenticated as ${req.username}.\n\n` +
36-
`You have requested information about ${subjects.length} ` +
37-
`${subjects.length === 1 ? "subject" : "subjects"}` +
38-
`${subjects.length > 0 ? ": " + subjects.join(", ") : ""}.`
39-
);
40-
} else {
41-
res.send(
42-
`You are not authenticated.\n\n` +
43-
`You have requested information about ${subjects.length} ` +
44-
`${subjects.length === 1 ? "subject" : "subjects"}` +
45-
`${subjects.length > 0 ? ": " + subjects.join(", ") : ""}.`
46-
);
47-
}
33+
const authenticationMessage = req.username
34+
? `You are authenticated as ${req.username}.`
35+
: "You are not authenticated.";
36+
37+
res.send(
38+
authenticationMessage + "\n\n" +
39+
`You have requested information about ${subjects.length} ` +
40+
`${subjects.length === 1 ? "subject" : "subjects"}` +
41+
`${subjects.length > 0 ? ": " + subjects.join(", ") : ""}.`
42+
);
4843
});
4944

5045
app.listen(PORT, () => {

0 commit comments

Comments
 (0)