Conversation
| const password = $("#password").val(); | ||
| const confirmPassword = $("#confirmPassword").val(); | ||
|
|
||
| if (username && password && confirmPassword) { |
There was a problem hiding this comment.
Is there any way we can simplify and remove some of these nested if/else blocks? A good way to get rid of else at least is to have the if block check for the unhappy/error path. once we've caught all the possible errors, we can simply add the logic for the happy path in the main body of the function. this would look something like this:
if (!username || !password || !confirmPassword) {
renderError("signup-error", "*Please complete all required fields.");
}
if (password !== confirmPassword) {
renderError("signup-error", "Passwords do not match. Try again.");
}
try {
const payload = {
username,
password,
};
const response = await fetch("/auth/signup", {
method: "POST",
body: JSON.stringify(payload),
headers: {
"Content-Type": "application/json",
},
});
const data = await response.json();
if (!data.success) {
renderError("signup-error", "Failed to create account. Try again.");
}
window.location.assign("/login");
} catch (error) {
renderError("signup-error", "Failed to create account. Try again.");
}
|
|
||
| let blogId; | ||
|
|
||
| if (target.is('a[name="blog-title"]')) { |
There was a problem hiding this comment.
What if this condition isn't true? blogId would be undefined when we run line 121
| } | ||
| }; | ||
|
|
||
| const handleAddComment = async (event, req, res) => { |
There was a problem hiding this comment.
why do we have req and res in here?
| const userId = each.userId; | ||
| const createdAt = each.createdAt; | ||
|
|
||
| blogs = { |
There was a problem hiding this comment.
This function isn't actually used anywhere..... but some feedback anyway!
Careful here with declaring variables without let or const!
We could refactor this whole fn though and just have:
const blogs = {
id: each.id,
title: each.title,
content: each.content,
userId: each.userId,
createdAt: each.createdAt,
}
Even better, just return the object, no need to declare a variable if we just want to return its value!
return {
id: each.id,
title: each.title,
content: each.content,
userId: each.userId,
createdAt: each.createdAt,
}
| const { username, password } = req.body; | ||
|
|
||
| if (!username || !password) { | ||
| renderError("signup-error", "Please complete all required fields."); |
There was a problem hiding this comment.
where is this function coming from?
No description provided.