-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.js
94 lines (82 loc) · 2.56 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const express = require("express")
const router = express.Router()
const transformerController = require("./controllers/transformerController")
const serviceController = require("./controllers/serviceController")
// ---index
router.get('/', async (req, res, next) => {
try {
res.status(200);
res.render("index");
} catch (error) {
console.error("TransformerController returned an error");
next(error);
}
});
// ---building
// form address
router.get('/adres', async (req, res, next) => {
res.render('address');
});
// search buildings
router.post('/gebouwen', async (req, res, next) => {
try {
res.status(200);
let response = await transformerController.getAdres(req.body);
res.send(response);
} catch (error) {
console.error("TransformerController returned an error");
next(error);
}
});
// search buildingunits
router.post('/gebouwunits', async (req, res, next) => {
try {
res.status(200);
let response = await transformerController.getGebouwEenheden(req.body)
console.log(JSON.stringify(req.body));
let params = {gebouwEenheidId : response.gebouweenheden[0].identificator.objectId, postcode: req.body.postcode, street: req.body.street, number: req.body.number};
let buildingResponse = await transformerController.getGebouwId(params)
res.send(buildingResponse)
} catch (error) {
console.error("TransformerController returned an error");
next(error);
}
});
// add info to building
router.get('/toevoegen', async (req, res, next) => {
res.render('info');
});
router.get('/postcode', async (req, res, next) => {
res.render('services');
});
router.post('/service/postcode', async (req, res, next) => {
try {
res.status(200)
var response = await serviceController.postCodeSearch(req.body);
res.send(response);
} catch (error) {
res.status(304)
var response = error.message;
}
})
router.post('/services/getservices', async(req, res, next) => {
try {
res.status(200)
let response = await serviceController.getServices(req.body)
res.send(response)
} catch (error) {
res.status(304)
next(error)
}
})
router.post('/services' ,async (req, res, next) => {
try {
res.status(200);
let response = await serviceController.addService(req.body);
res.send(response)
} catch (error) {
console.error("TransformerController returned an error");
next(error);
}
});
module.exports = router