-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
89 lines (73 loc) · 3.13 KB
/
index.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
'use strict';
const express = require('express'),
app = express(),
bodyParser = require('body-parser'),
cors = require('cors'),
port = process.env.PORT || 8080,
server = process.env.LVM_PUBLIC_URL || `http://localhost:${port}`;
const repositories = require('./repositories')(server);
const PartnerController = require('./controllers/partner'),
AngeboteController = require('./controllers/angebote'),
VertraegeController = require('./controllers/vertraege'),
BerufeController = require('./controllers/berufe'),
SchadenController = require('./controllers/schaden'),
BriefkastenController = require('./controllers/briefkasten'),
AntraegeController = require('./controllers/antraege');
const partnerController = new PartnerController(repositories),
angeboteController = new AngeboteController(repositories),
vertraegeController = new VertraegeController(repositories),
berufeController = new BerufeController(repositories),
schadenController = new SchadenController(repositories),
briefkastenController = new BriefkastenController(repositories),
antraegeController = new AntraegeController(repositories);
// middlewares
app.use(cors());
app.use(bodyParser.json());
app.use(function (req, res, next) {
setTimeout(function () {
next();
}, 100);
});
app.use(function (req, res, next) {
console.log(`${req.method}: ${req.url}`);
next();
});
// Partner
// Query Parameter: q=Suchbegriff
app.get('/partners', partnerController.list);
app.get('/partner/:id', partnerController.get);
app.get('/partner/:id/haushalt', partnerController.getHaushalt);
app.get('/partner/:id/kontakt', partnerController.getKontakte);
// Angebote
// Query Parameter: partnerId=partnerId&mode=(list|count)
app.get('/angebote', angeboteController.getListOrCount);
app.get('/angebot/:id', angeboteController.get);
// Query Parameter: partnerId=partnerId
app.get('/angebot/:sparte/vorbelegung', angeboteController.getVorbelegung);
app.post('/angebot/:sparte/berechnen', angeboteController.berechnen);
app.post('/angebot', angeboteController.create);
app.post('/angebot/:id', angeboteController.copy);
// Antraege
// Query Parameter: partnerId=partnerId&mode=(list|count)
app.get('/antraege', antraegeController.getListOrCount);
// Verträge
// Query Parameter: partnerId=partnerId&mode=(list|count)
app.get('/vertraege', vertraegeController.getListOrCount);
app.get('/vertrag/:id', vertraegeController.get);
app.get('/vertrag/:id/briefvorlagen', vertraegeController.getBriefvorlagen);
app.get('/vertrag/:id/briefempfaenger', vertraegeController.getBriefempfaenger);
// Berufe
// Query Parameter: q=Suchbegriff
app.get('/berufe', berufeController.list);
// Schäden
// Query Parameter: partnerId=partner&vsnr=vertragId
app.get('/schaden/:sparte/vorbelegung', schadenController.getVorbelegung);
app.post('/schaden', schadenController.create);
// Briefkasten
app.get('/briefkasten/:id', briefkastenController.list);
module.exports = app;
if (module.parent === null || module.parent.filename.indexOf('server.js') > -1) {
app.listen(port, () => {
console.log(`server running on port ${port} (http://${server})`);
});
}