Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chapter 5 - error handling - validateIssue function #53

Open
MSKhodadady opened this issue Sep 12, 2018 · 1 comment
Open

chapter 5 - error handling - validateIssue function #53

MSKhodadady opened this issue Sep 12, 2018 · 1 comment

Comments

@MSKhodadady
Copy link

If we see this part of validateIssue function:

for (const field in issueFieldType) {
    const type = issueFieldType[field];
    if (!type) {
      delete issue[field];
    } else if (type === 'required' && !issue[field]) {
      return `${field} is required.`;
    }
  }

we see that the if (!type) is redundant. because every type in issueFieldType is not undefind .
I think we should write issue instead of issueFieldType in the for statement:

for (const field in issue) {
    const type = issueFieldType[field];
    if (!type) {
      delete issue[field];
    } else if (type === 'required' && !issue[field]) {
      return `${field} is required.`;
    }
  }

The resulted function is:

function validateIssue(issue) {
  for (const field in issue) {
    const type = issueFieldType[field];
    if (!type) {
      delete issue[field];
    } else if (type === 'required' && !issue[field]) {
      return `${field} is required.`;
    }
  }
  if (!validIssueStatus[issue.status])
    return `${issue.status} is not a valid status.`;
  return null;
}
@edusantana
Copy link

I think it was an error, instead of:

for (const field in issueFieldType) {

it should be:

for(const field in issue){

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

No branches or pull requests

2 participants