Skip to content

Commit

Permalink
Integrate new launch with front end
Browse files Browse the repository at this point in the history
  • Loading branch information
odziem committed Mar 20, 2021
1 parent 87dcd78 commit 96f9657
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
16 changes: 14 additions & 2 deletions client/src/hooks/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ async function httpGetLaunches() {
});
}

// Submit given launch data to launch system.
async function httpSubmitLaunch(launch) {
// TODO: Once API is ready.
// Submit given launch data to launch system.
try {
return await fetch(`${API_URL}/launches`, {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(launch),
});
} catch(err) {
return {
ok: false,
};
}
}

async function httpAbortLaunch(id) {
Expand Down
5 changes: 2 additions & 3 deletions client/src/hooks/useLaunches.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function useLaunches(onSuccessSound, onAbortSound, onFailureSound) {

const submitLaunch = useCallback(async (e) => {
e.preventDefault();
// setPendingLaunch(true);
setPendingLaunch(true);
const data = new FormData(e.target);
const launchDate = new Date(data.get("launch-day"));
const mission = data.get("mission-name");
Expand All @@ -34,8 +34,7 @@ function useLaunches(onSuccessSound, onAbortSound, onFailureSound) {
target,
});

// TODO: Set success based on response.
const success = false;
const success = response.ok;
if (success) {
getLaunches();
setTimeout(() => {
Expand Down
2 changes: 1 addition & 1 deletion server/src/models/launches.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const launch = {
mission: 'Kepler Exploration X',
rocket: 'Explorer IS1',
launchDate: new Date('December 27, 2030'),
destination: 'Kepler-442 b',
target: 'Kepler-442 b',
customer: ['ZTM', 'NASA'],
upcoming: true,
success: true,
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/launches/launches.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function httpAddNewLaunch(req, res) {
const launch = req.body;

if (!launch.mission || !launch.rocket || !launch.launchDate
|| !launch.destination) {
|| !launch.target) {
return res.status(400).json({
error: 'Missing required launch property',
});
Expand Down

0 comments on commit 96f9657

Please sign in to comment.