-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
137 lines (108 loc) · 3.09 KB
/
app.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var search = require('search-flix-locations');
var flix = require('flix');
var adapter = require('db-flix-cities');
var moment = require('moment');
var app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.get('/flix/query/:typed', async function (req, res, next) {
var typed = req.params.typed;
var result = await search(typed, null, true);
res.status(200).send({
success: 'true',
message: result
});
});
app.get('/flix/query/:typed/:limit', async function (req, res, next) {
var typed = req.params.typed;
var limit = req.params.limit;
var result = await search(typed, limit, true);
res.status(200).send({
success: 'true',
message: result
});
});
app.get('/flix/journey/:fromID/:fromType/:toID/:toType', async function (req, res, next) {
var fromID = {
type: req.params.fromType,
id: req.params.fromID
};
var toID = {
type: req.params.toType,
id: req.params.toID
};
var result = await flix.journeys(fromID, toID);
res.status(200).send({
success: 'true',
message: result
});
});
app.get('/flix/journey/:fromID/:fromType/:toID/:toType/:when', async function (req, res, next) {
var fromID = {
type: req.params.fromType,
id: req.params.fromID
};
var toID = {
type: req.params.toType,
id: req.params.toID
};
var when = req.params.when;
var option = {
when: moment(when).toDate()
};
var result = await flix.journeys(fromID, toID, option);
res.status(200).send({
success: 'true',
message: result
});
});
app.get('/flix/journey/:fromID/:fromType/:toID/:toType/:when/:language', async function (req, res, next) {
var fromID = {
type: req.params.fromType,
id: req.params.fromID
};
var toID = {
type: req.params.toType,
id: req.params.toID
};
var when = req.params.when;
var option = {
when: moment(when).toDate(),
language: req.params.language
};
var result = await flix.journeys(fromID, toID, option);
res.status(200).send({
success: 'true',
message: result
});
});
app.get('/flix/convert/dbtoflix/:ID', async function (req, res, next) {
var ID = req.params.ID;
var result = await adapter.toFlix(ID).catch((res) => {
res.status(200).send({
success: 'false',
message: "No Station found.",
result: res
});
});
res.status(200).send({
success: 'true',
message: result
});
});
app.get('/flix/convert/flixtodb/:ID', async function (req, res, next) {
var ID = req.params.ID;
var result = await adapter.toDB(ID);
res.status(200).send({
success: 'true',
message: result
});
});
module.exports = app;