-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
41 lines (37 loc) · 1.04 KB
/
api.js
File metadata and controls
41 lines (37 loc) · 1.04 KB
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
import express from "express";
import { diff, dayDiff, history } from "./index.js";
import { log } from "./logger.js";
export async function startHttpApi() {
const app = express();
app.get("/api/v1/getDayDiff", (_req, res) => {
const dayDiffFlat = {};
for(const date of Object.keys(dayDiff)) {
dayDiffFlat[date] = {
...dayDiff[date].subjects
}
}
res.send({
success: true,
data: dayDiffFlat
});
});
app.get("/api/v1/getDayDiffForDate/:date", (req, res) => {
const date = req.params.date;
if(dayDiff[date]) {
res.send({
success: true,
data: dayDiff[date].subjects || {}
});
}else{
res.send({
success: false,
data: {
error: "No data for provided date or invalid date"
}
});
}
});
app.listen(4080, ()=>{
log(1, "Started HTTP server on port 4080.");
})
}