-
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tests): remove trailing semi-colons for consistency
- Loading branch information
Showing
15 changed files
with
180 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const { server } = require('./consumer.js'); | ||
const { server } = require('./consumer.js') | ||
|
||
server.listen(8080, () => { | ||
console.log('Animal Matching Service listening on http://localhots:8080'); | ||
}); | ||
console.log('Animal Matching Service listening on http://localhots:8080') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const bodyParser = require('body-parser'); | ||
const Repository = require('./repository'); | ||
const express = require('express') | ||
const cors = require('cors') | ||
const bodyParser = require('body-parser') | ||
const Repository = require('./repository') | ||
|
||
const server = express(); | ||
server.use(cors()); | ||
server.use(bodyParser.json()); | ||
const server = express() | ||
server.use(cors()) | ||
server.use(bodyParser.json()) | ||
server.use(bodyParser.urlencoded({ | ||
extended: true | ||
})); | ||
})) | ||
server.use((req, res, next) => { | ||
res.header('Content-Type', 'application/json; charset=utf-8'); | ||
next(); | ||
}); | ||
res.header('Content-Type', 'application/json charset=utf-8') | ||
next() | ||
}) | ||
|
||
const animalRepository = new Repository(); | ||
const animalRepository = new Repository() | ||
|
||
// Load default data into a repository | ||
const importData = () => { | ||
const data = require('./data/animalData.json'); | ||
const data = require('./data/animalData.json') | ||
data.reduce((a, v) => { | ||
v.id = a + 1; | ||
animalRepository.insert(v); | ||
return a + 1; | ||
}, 0); | ||
}; | ||
v.id = a + 1 | ||
animalRepository.insert(v) | ||
return a + 1 | ||
}, 0) | ||
} | ||
|
||
// List all animals with 'available' eligibility | ||
const availableAnimals = () => { | ||
return animalRepository.fetchAll().filter(a => { | ||
return a.eligibility.available; | ||
}); | ||
}; | ||
return a.eligibility.available | ||
}) | ||
} | ||
|
||
// Get all animals | ||
server.get('/animals', (req, res) => { | ||
res.json(animalRepository.fetchAll()); | ||
}); | ||
res.json(animalRepository.fetchAll()) | ||
}) | ||
|
||
// Get all available animals | ||
server.get('/animals/available', (req, res) => { | ||
res.json(availableAnimals()); | ||
}); | ||
res.json(availableAnimals()) | ||
}) | ||
|
||
// Find an animal by ID | ||
server.get('/animals/:id', (req, res) => { | ||
const response = animalRepository.getById(req.params.id); | ||
const response = animalRepository.getById(req.params.id) | ||
if (response) { | ||
res.end(JSON.stringify(response)); | ||
res.end(JSON.stringify(response)) | ||
} else { | ||
res.writeHead(404); | ||
res.end(); | ||
res.writeHead(404) | ||
res.end() | ||
} | ||
}); | ||
}) | ||
|
||
// Register a new Animal for the service | ||
server.post('/animals', (req, res) => { | ||
const animal = req.body; | ||
const animal = req.body | ||
|
||
// Really basic validation | ||
if (!animal || !animal.first_name) { | ||
res.writeHead(400); | ||
res.end(); | ||
res.writeHead(400) | ||
res.end() | ||
|
||
return; | ||
return | ||
} | ||
|
||
animal.id = animalRepository.fetchAll().length; | ||
animalRepository.insert(animal); | ||
animal.id = animalRepository.fetchAll().length | ||
animalRepository.insert(animal) | ||
|
||
res.writeHead(200); | ||
res.end(); | ||
}); | ||
res.writeHead(200) | ||
res.end() | ||
}) | ||
|
||
module.exports = { | ||
server, | ||
importData, | ||
animalRepository | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const { server, importData } = require('./provider.js'); | ||
importData(); | ||
const { server, importData } = require('./provider.js') | ||
importData() | ||
|
||
server.listen(8081, () => { | ||
console.log('Animal Profile Service listening on http://localhost:8081'); | ||
}); | ||
console.log('Animal Profile Service listening on http://localhost:8081') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
// Simple object repository | ||
class Repository { | ||
constructor() { | ||
this.entities = []; | ||
this.entities = [] | ||
} | ||
|
||
fetchAll() { | ||
return this.entities; | ||
return this.entities | ||
} | ||
|
||
getById(id) { | ||
return this.entities.find((entity) => id == entity.id); | ||
return this.entities.find((entity) => id == entity.id) | ||
} | ||
|
||
insert(entity) { | ||
this.entities.push(entity); | ||
this.entities.push(entity) | ||
} | ||
|
||
clear() { | ||
this.entities = []; | ||
this.entities = [] | ||
} | ||
} | ||
|
||
module.exports = Repository; | ||
module.exports = Repository |
Oops, something went wrong.