-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
71 lines (56 loc) · 1.91 KB
/
server.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
var express = require('express');
var bodyParser = require('body-parser');
var calc = require('./modules/Calc');
var tranportationType = require('./staitcInfo/TranportationType');
var transportationArea = require('./staitcInfo/TranportationCarArea');
var passengersCost = require('./staitcInfo/PasengersConst');
var TransportationRefund = require('./db/TransportationRefund');
var mongoose = require('mongoose');
mongoose.connect('mongodb://fadeI:fadesa12@ds125181.mlab.com:25181/ransporationrefunds');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
console.log("we are connected")
});
const app = express();
app.use('/static', express.static('./server/static'));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// parse application/json
app.use(bodyParser.json())
app.get('/api/reportData', (req, res) => {
const products = [{
id: 1,
date: "7/6/18",
type: 'Car',
area: 50,
passengerNumber: 3,
addtionalCost: 5
}];
const refuds = [];
TransportationRefund.find({}, function (err, data) {
if (err) {
console.log(err);
}
else {
console.log(data);
res.json(data);
}
});
});
app.get('/api/transportationArea', (req, res) => {
res.json(transportationArea.TranportationCarArea);
});
app.get('/api/transporationTypes', (req, res) => {
res.json(tranportationType.TransportationType);
});
app.get('/api/transporationPassengers', (req, res) => {
res.json(passengersCost.PassengersCost);
});
// Post Request
app.post('/api/processData', (req, res) => {
calc.getRequest(req.body.trasnporationDetails);
res.json(200);
});
const port = 5000;
app.listen(port, () => console.log('server started on port 5000'));