Skip to content

Commit

Permalink
Merge pull request #147 from oSoc18/develop
Browse files Browse the repository at this point in the history
Hotfix #2
  • Loading branch information
ThibaultLesuisse authored Jul 19, 2018
2 parents 133e05b + 6aea168 commit 2fcffe3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
22 changes: 19 additions & 3 deletions controllers/serviceController.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
const transformer = require("../helpers/transformer")
const fs = require('fs');
const fs = require("fs");

exports.addService = async (params) => {
return await transformer.makeService(params);
}

exports.postCodeSearch = async (params) => {
exports.postCodeSearch = (params) => {
return new Promise((resolve, reject) => {
fs.readdir(__dirname + "/../files/", (err, files) => {
if(err) reject()
fs.readdir(__dirname + `/../files/${params.postcode}/gebouwen/`, (err, files) => {
if(err) reject("Geen gebouwen gevonden voor psotcode");
let response = {}
files.forEach(file => {
fs.readFile(__dirname + `/../files/${params.postcode}/gebouwen/${file}`, (err, data) => {
if(err) reject("Problemen bij het openen van gebouwfile");
response.push(JSON.parse(data));
})
})
resolve(response);
})
})
})
}
2 changes: 1 addition & 1 deletion files/service-example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[{
"@context": "http://schema.org/",
"@context": "https://schema.org/",
"@id": "https://stad.gent/id/products/123",
"@type": "Service",
"name": "Public toilet library",
Expand Down
2 changes: 1 addition & 1 deletion helpers/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function jsonLDBuilding(gebouwId, adresId, location) {
"xsd": "http://www.w3.org/2001/XMLSchema#"
},
"@id": "gebouw:" + gebouwId,
"type": "gebouw:Gebouw",
"@type": "gebouw:Gebouw",
"gebouw:Gebouw.adres": {
"@id": "http://data.vlaanderen.be/id/adres/" + adresId,
"@type": "http://www.w3.org/ns/locn#Address",
Expand Down
9 changes: 8 additions & 1 deletion routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ router.get('/postcode', async (req, res, next) => {
});

router.post('/service/postcode', async (req, res, next) => {
await serviceController
try {
res.status(200)
var response = await serviceController.postCodeSearch(req.body);
} catch (error) {
res.status(304)
var response = error.message;
}
res.send(response);
})
router.post('/services', async (req, res, next) => {
try {
Expand Down

0 comments on commit 2fcffe3

Please sign in to comment.