nss-evening-cohort-11 / nutshell-ewoks-droids

Star Destroyer
0 stars 2 forks source link

Add Planetary Sector to a Mission Axios.post #114

Open Nikababy01 opened 4 years ago

Nikababy01 commented 4 years ago

USER STORY

As a user, I should be able to add a Planetary Sector to a Mission.

AC

WHEN the page loads I should see all missions THEN click a button to planetary sectors AND click a button to return back to my boards

WIREFRAMES

DEV NOTES


// 1. make smash function called getMissionsPlanetarySectors
// 2. move missionData.getMissions into that smash function - nothing should look different
// 3. in smash function - getMissionPlanetarySectors getAllPlanetarySectors
// 4. smash function to return an array of mission objects- each mission object should have an
// array of PlanetarySectors  Each PlanetarySectors should have a boolean isChecked (true if that personnel is on that mission)
// 5.  modify domstring to show checkboxes
// 6.  when a checkbox is checked - POST to missionPlanetarySectors collection
// 7.  when a checkbox is unchecked - DELETE to missionPlanetarySectors collection

Create a controller function:
const missionPlanetarySectorsController = (e) => {
  e.preventDefault();
  // console.log(e.target.dataset);
  if (e.target.checked) {
    // create a new missionPlanetarySectors
    const newmissionPlanetarySectors = {
     PlanetarySectorsId: e.target.closest('.card').id,
      PlanetarySectorsId: e.target.dataset.PlanetarySectorsId // data-PlanetarySectors-id
    };
    missionPlanetarySectors.addmissionPlanetarySectorsl(newmissionPlanetarySectors)
      .then(() => {
        // eslint-disable-next-line no-use-before-define
        buildPlanetarySectors();
        utils.printToDom('new-PlanetarySectors', '');
        utils.printToDom('personnel-div', '');
      })
      .catch((err) => console.error('could not create mission PlanetarySectors', err));
  } else {
    // delete a missionPersonnel
    const missionPersonnelId = e.target.id;
   missionPlanetarySectorsData.deletemissionPlanetarySectorsl(missionPlanetarySectorsId)
      .then(() => {
        // eslint-disable-next-line no-use-before-define
        printPlanetarySectors();
        utils.printToDom('new-PlanetarySectors', '');
        utils.printToDom('personnel-div', '');
      })
      .catch((err) => console.error('could not delete mission PlanetarySectors', err));
  }
};

RELATED TICKETS

EX. #1