Skip to content

Comments

project ready for checking#1

Open
C-Sim wants to merge 22 commits intomainfrom
dev
Open

project ready for checking#1
C-Sim wants to merge 22 commits intomainfrom
dev

Conversation

@C-Sim
Copy link
Owner

@C-Sim C-Sim commented Jul 1, 2022

No description provided.

const password = $("#password").val();
const confirmPassword = $("#confirmPassword").val();

if (username && password && confirmPassword) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this condition isn't true? blogId would be undefined when we run line 121

}
};

const handleAddComment = async (event, req, res) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have req and res in here?

const userId = each.userId;
const createdAt = each.createdAt;

blogs = {
Copy link

@natasha-mann natasha-mann Aug 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this function coming from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants