-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapis.js
111 lines (94 loc) · 4.48 KB
/
apis.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
const logger = require('winston');
const express = require('express');
const exUtils = require('./utils/expressUtils');
exports.router = () => {
logger.trace('in API.JS');
const router = new express.Router();
// test API
logger.info('ROUTE: /test');
const apiTest = require('./apis/apiTest');
router.route('/test')
.all(exUtils.catchAsyncErrors(apiTest.all))
.get(exUtils.catchAsyncErrors(apiTest.get))
.put(exUtils.catchAsyncErrors(apiTest.put))
.post(exUtils.catchAsyncErrors(apiTest.post))
.delete(exUtils.catchAsyncErrors(apiTest.delete));
// weather API
const weatherAPI = require('./apis/weather');
logger.info('ROUTE: /weather/forecast');
router.route('/weather/forecast')
.all(exUtils.catchAsyncErrors(weatherAPI.all))
.get(exUtils.catchAsyncErrors(weatherAPI.getWeather));
logger.info('ROUTE: /weather/forecast/{ID}');
router.route('/weather/forecast/:locationID')
.all(exUtils.catchAsyncErrors(weatherAPI.all))
.get(exUtils.catchAsyncErrors(weatherAPI.getLocationWeather));
logger.info('ROUTE: /weather/locations');
router.route('/weather/locations')
.all(exUtils.catchAsyncErrors(weatherAPI.all))
.post(exUtils.catchAsyncErrors(weatherAPI.notImplemented))
.get(exUtils.catchAsyncErrors(weatherAPI.getLocations));
logger.info('ROUTE: /weather/locations/{ID}');
router.route('/weather/locations/:locationID')
.all(exUtils.catchAsyncErrors(weatherAPI.all))
.put(exUtils.catchAsyncErrors(weatherAPI.notImplemented))
.delete(exUtils.catchAsyncErrors(weatherAPI.deleteLocation));
// news API
const articlesAPI = require('./apis/articles');
logger.info('ROUTE: /news/articles');
router.route('/news/articles')
.all(exUtils.catchAsyncErrors(articlesAPI.all))
.get(exUtils.catchAsyncErrors(articlesAPI.get));
logger.info('ROUTE: /news/articles/{ID}');
router.route('/news/articles/:articleID')
.all(exUtils.catchAsyncErrors(articlesAPI.allID))
.get(exUtils.catchAsyncErrors(articlesAPI.getID));
logger.info('ROUTE: /news/sources');
router.route('/news/sources')
.all(exUtils.catchAsyncErrors(articlesAPI.all))
.post(exUtils.catchAsyncErrors(articlesAPI.postSources))
.get(exUtils.catchAsyncErrors(articlesAPI.getSources));
logger.info('ROUTE: /news/sources/{ID}');
router.route('/news/sources/:sourceID')
.all(exUtils.catchAsyncErrors(articlesAPI.all))
.put(exUtils.catchAsyncErrors(articlesAPI.putSourcesID))
.delete(exUtils.catchAsyncErrors(articlesAPI.deleteSourcesID));
logger.info('ROUTE: /news/sources/{ID}');
router.route('/news/sources/:sourceID/articles')
.all(exUtils.catchAsyncErrors(articlesAPI.all))
.get(exUtils.catchAsyncErrors(articlesAPI.getSourcesIDArticles));
// home management API
logger.info('ROUTE: /home');
const homeAPI = require('./apis/home');
router.route('/home')
.all(exUtils.catchAsyncErrors(homeAPI.all))
.get(exUtils.catchAsyncErrors(homeAPI.get))
.put(exUtils.catchAsyncErrors(homeAPI.put));
logger.info('ROUTE: /home/rooms');
const roomsAPI = require('./apis/rooms');
router.route('/home/rooms')
.all(exUtils.catchAsyncErrors(roomsAPI.all))
.get(exUtils.catchAsyncErrors(roomsAPI.get))
.post(exUtils.catchAsyncErrors(roomsAPI.post));
logger.info('ROUTE: /home/rooms/{roomID}');
const roomAPI = require('./apis/room-id');
router.route('/home/rooms/:roomID')
.all(exUtils.catchAsyncErrors(roomAPI.all))
.get(exUtils.catchAsyncErrors(roomAPI.get))
.put(exUtils.catchAsyncErrors(roomAPI.put))
.delete(exUtils.catchAsyncErrors(roomAPI.delete));
logger.info('ROUTE: /home/rooms/{roomID}/devices');
const devicesAPI = require('./apis/devices');
router.route('/home/rooms/:roomID/devices')
.all(exUtils.catchAsyncErrors(devicesAPI.all))
.get(exUtils.catchAsyncErrors(devicesAPI.get))
.post(exUtils.catchAsyncErrors(devicesAPI.post));
logger.info('ROUTE: /home/rooms/{roomID}/devices/{deviceID}');
const deviceAPI = require('./apis/device-id');
router.route('/home/rooms/:roomID/devices/:deviceID')
.all(exUtils.catchAsyncErrors(deviceAPI.all))
.get(exUtils.catchAsyncErrors(deviceAPI.get))
.put(exUtils.catchAsyncErrors(deviceAPI.put))
.delete(exUtils.catchAsyncErrors(deviceAPI.delete));
return router;
}