-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.ts
69 lines (54 loc) · 2.63 KB
/
router.ts
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
import { Router } from './dependencies.ts';
import { getPlanets } from './planets.ts';
import { abortLaunch, getLaunch, getLaunches, scheduleLaunch } from './launches.ts';
const router = new Router();
router.get('/', context => {
context.response.body = `
:::=== :::==== :::==== :::===== :::===== :::======= ::: :::===
::: ::: === ::: === ::: ::: ::: === === ::: :::
===== ======= ======== === ====== ======== === === === === =====
=== === === === === === === === === ===
====== === === === ======= ======== === === === ======
:::=== ::: :::==== :::= === :::===== :::==== :::= ===
::: ::: ::: === :::===== ::: ::: === :::=====
===== === === === ======== ======== ======== === === === ========
=== === === === === ==== === === === === ====
====== === ====== === === ======= ====== === ===
:::==== :::==== :::==== :::
:::==== ::: === ::: === :::
=== ======= === === ===
=== === === === === ===
=== === === ====== ========
=== :::==== :::===== :::= === :::==== ===
=== ::: === ::: :::===== ::: === ===
=== === === ====== ======== === === ===
=== === === === === ==== === === ===
=== ======= ======== === === ====== ===
`;
});
router.get('/planets', context => {
context.response.body = getPlanets();
});
router.get('/launches', context => {
context.response.body = getLaunches();
});
router.get('/launches/:ID', context => {
if (context.params?.ID) {
const launch = getLaunch(Number(context.params.ID));
if (launch) context.response.body = launch;
else context.throw(404, 'error getting launch');
};
});
router.post('/launches', async context => {
const body = await context.request.body().value;
scheduleLaunch(body);
context.response.status = 201;
context.response.body = {success: true};
});
router.delete('/launches/:ID', context => {
if (context.params?.ID) {
const launch = abortLaunch(Number(context.params.ID));
context.response.body = {success: launch};
};
});
export default router;