From e57fabd26aee0b0a1918993e1d41b32f0054b6a7 Mon Sep 17 00:00:00 2001 From: Hinekureta Date: Fri, 18 Mar 2016 11:41:33 +0100 Subject: [PATCH 1/4] Early commit --- exercises/nodejs/02-interactive/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/exercises/nodejs/02-interactive/index.js b/exercises/nodejs/02-interactive/index.js index 2efda33..390bff4 100755 --- a/exercises/nodejs/02-interactive/index.js +++ b/exercises/nodejs/02-interactive/index.js @@ -29,10 +29,16 @@ prompt.get([{ console.log(`Welcome, ${result.name} !`); - tryAgain(function() {}); + tryAgain(function(n, b) {again(n, b)}); }); +function again(n, b) +{ + if (!b) + tryAgain(again); +} + function tryAgain(callback) { prompt.get( [{ name: 'value', From 952a18e432d35c8648221516517bcfb275681f16 Mon Sep 17 00:00:00 2001 From: Hinekureta Date: Fri, 18 Mar 2016 12:16:35 +0100 Subject: [PATCH 2/4] Commit Ex3 Done --- exercises/nodejs/03-promise/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/exercises/nodejs/03-promise/index.js b/exercises/nodejs/03-promise/index.js index 5ab1b33..c35091b 100755 --- a/exercises/nodejs/03-promise/index.js +++ b/exercises/nodejs/03-promise/index.js @@ -44,7 +44,7 @@ function askUser() { } ], function (choices) { console.log(choices); - + resolve(choices); // TODO resolve the promise !!! // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise }); @@ -60,9 +60,19 @@ function fetchData(choices) { const spinner = ora('Fetching StarWars API...'); spinner.start(); + return fetch(url) + .then(function onResponse(response) { + if(response.ok) + { + spinner.stop(); + return response.json(); + } + else + throw new Error('Network response was not ok.'); + }); // TODO now use the fetch API : // https://developer.mozilla.org/fr/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful - return Promise.reject(new Error('fetchData not implemented !')); + //return Promise.reject(new Error('fetchData not implemented !')); } function displayResults(data) { From a4c6cec9d6e377e0ab446daffc739b4ed6430d2a Mon Sep 17 00:00:00 2001 From: Hinekureta Date: Fri, 18 Mar 2016 12:51:50 +0100 Subject: [PATCH 3/4] Start to modify api --- exercises/nodejs/05-express_routing/api/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/exercises/nodejs/05-express_routing/api/index.js b/exercises/nodejs/05-express_routing/api/index.js index 243238a..e580dad 100755 --- a/exercises/nodejs/05-express_routing/api/index.js +++ b/exercises/nodejs/05-express_routing/api/index.js @@ -14,7 +14,21 @@ const router = module.exports = new express.Router(); ///////////////////////////////////////////// router.get('/', (req, res) => { - res.send('hello from API sub-router !'); + res.send(` + + + meta routes + + +

COUCOU

+`); + // TODO a small page listing your endpoints // cf. js-class-2016-episode-2\src\server\common\meta-routes.js }); From e9e619e8924483eb4d93cac92a124405550b87ff Mon Sep 17 00:00:00 2001 From: Hinekureta Date: Sun, 20 Mar 2016 17:26:02 +0100 Subject: [PATCH 4/4] Adds 9 NBA teams in API --- .../nodejs/05-express_routing/api/index.js | 68 ++++++++++++++++++- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/exercises/nodejs/05-express_routing/api/index.js b/exercises/nodejs/05-express_routing/api/index.js index e580dad..5a5e61e 100755 --- a/exercises/nodejs/05-express_routing/api/index.js +++ b/exercises/nodejs/05-express_routing/api/index.js @@ -26,15 +26,77 @@ router.get('/', (req, res) => { } -

COUCOU

+

NBA TEAMS API

+
  • ${req.baseUrl}/spurs +
  • ${req.baseUrl}/warriors +
  • ${req.baseUrl}/lakers +
  • ${req.baseUrl}/knicks +
  • ${req.baseUrl}/clippers +
  • ${req.baseUrl}/76ers +
  • ${req.baseUrl}/bulls +
  • ${req.baseUrl}/hawks +
  • ${req.baseUrl}/celtics + + + + `); // TODO a small page listing your endpoints // cf. js-class-2016-episode-2\src\server\common\meta-routes.js }); - - +var teams = [ +{name : 'Spurs', city: 'San Antonio', numberOfTitles : '5', currentCoach : 'Greg Popovitch', stadium : 'AT&T Center'}, +{name : 'Warriors', city: 'Oakland', numberOfTitles : '4', currentCoach : 'Steve Kerr', stadium : 'Oracle Arena'}, +{name : 'Lakers', city: 'Los Angeles', numberOfTitles : '16', currentCoach : 'Byron Scott', stadium : 'Staples Center'}, +{name : 'Knicks', city: 'New York', numberOfTitles : '2', currentCoach : 'Kurt Rambis', stadium : 'Madison Square Garden'}, +{name : 'Clippers', city: 'Los Angeles', numberOfTitles : '0', currentCoach : 'Doc Rivers', stadium : 'Staples Center'}, +{name : '76ers', city: 'Philadelphia', numberOfTitles : '3', currentCoach : 'Brett Brown', stadium : 'Wells Fargo Center'}, +{name : 'Bulls', city: 'Chicago', numberOfTitles : '6', currentCoach : 'Fred Hoiberg', stadium : 'United Center'}, +{name : 'Hawks', city: 'Atlanta', numberOfTitles : '1', currentCoach : 'Mike Budenholzer', stadium : 'Philips Arena'}, +{name : 'Celtics', city: 'Boston', numberOfTitles : '17', currentCoach : 'Brad Stevens', stadium : 'TD Garden'}, +]; + +router.get('/spurs', function(req, res){ + res.json(teams[0]); +}) + +router.get('/warriors', function(req, res){ + res.json(teams[1]); +}) + +router.get('/lakers', function(req, res){ + res.json(teams[2]); +}) + +router.get('/knicks', function(req, res){ + res.json(teams[3]); +}) + +router.get('/clippers', function(req, res){ + res.json(teams[4]); +}) + +router.get('/76ers', function(req, res){ + res.json(teams[5]); +}) + +router.get('/bulls', function(req, res){ + res.json(teams[6]); +}) + +router.get('/hawks', function(req, res){ + res.json(teams[7]); +}) + +router.get('/celtics', function(req, res){ + res.json(teams[8]); +}) // TODO one or two routes // be creative !