{"size": 1545, "ext": "js", "max_stars_repo_path": "public/js/edit-district.js", "max_stars_repo_name": "JXIong15/gradright", "max_stars_repo_stars_event_min_datetime": "2021-05-19T21:32:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-19T21:32:02.000Z", "max_issues_repo_path": "public/js/edit-district.js", "max_issues_repo_name": "JXIong15/gradright", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/js/edit-district.js", "max_forks_repo_name": "JXIong15/gradright", "max_forks_repo_forks_event_min_datetime": "2021-05-17T23:07:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-19T20:54:35.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 37.6829268293, "max_line_length": 103, "alphanum_fraction": 0.6660194175}

async function editDistrict(event) {
    event.preventDefault();

    const id = window.location.toString().split('/')[window.location.toString().split('/').length - 1];

    const district_name = document.querySelector('#district-name').value;
    const math_credit_to_graduate = document.querySelector('#math').value;
    const english_credit_to_graduate = document.querySelector('#english').value;
    const science_credit_to_graduate = document.querySelector('#science').value;
    const social_studies_credit_to_graduate = document.querySelector('#ss').value;
    const pe_credit_to_graduate = document.querySelector('#pe').value;
    const health_credit_to_graduate = document.querySelector('#health').value;
    const elective_credit_to_graduate = document.querySelector('#elective').value;

      const response = await fetch(`/api/district/${id}`, {
        method: 'PUT',
        body: JSON.stringify({
            district_name,
            math_credit_to_graduate,
            english_credit_to_graduate,
            science_credit_to_graduate,
            social_studies_credit_to_graduate,
            pe_credit_to_graduate,
            health_credit_to_graduate,
            elective_credit_to_graduate,
        }),
        headers: {
            'Content-Type': 'application/json'
        }
      });
      
      if (response.ok) {
        document.location.replace(`/district/${id}`);
      } else {
        alert(response.statusText);
      }
  }


document.querySelector('#edit-btn').addEventListener('click', editDistrict);