forked from satyawikananda/rs-bed-covid-indo-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.ts
42 lines (37 loc) · 1.38 KB
/
handler.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
import type { Handler } from "vite-plugin-mix";
import { getProvinces } from "./src/scrape/get-provinces";
import { getCities } from "./src/scrape/get-cities";
import { getHospitalList } from "./src/scrape/hospitals";
import { getBedDetail } from "./src/scrape/bed-detail";
import { getHospitalMap } from "./src/scrape/hospital-map";
export const handler: Handler = async (req, res, next) => {
if (req.path === "/api/get-provinces") {
const data = await getProvinces();
return res.end(JSON.stringify(data));
}
if (req.path === "/api/get-cities") {
const { provinceid } = req.query;
const data = await getCities(provinceid as string);
return res.end(JSON.stringify(data));
}
if (req.path === "/api/get-hospitals") {
const { type, provinceid, cityid } = req.query;
const data = await getHospitalList({
type: +type as number,
provinceid: provinceid as string,
cityid: cityid as string,
});
return res.end(JSON.stringify(data));
}
if (req.path === "/api/get-bed-detail") {
const { type, hospitalid } = req.query;
const data = await getBedDetail(hospitalid as string, +type as number);
return res.end(JSON.stringify(data));
}
if (req.path === "/api/get-hospital-map") {
const { hospitalid } = req.query;
const data = await getHospitalMap(hospitalid as string);
return res.end(JSON.stringify(data));
}
next();
};