This repository has been archived by the owner on May 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
74 lines (58 loc) · 1.89 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
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const multer = require("multer"); // v1.0.5
const lib = require("./lib");
const winston = require("./config/winston.js");
const morganConfig = require("./config/morgan");
const upload = multer(); // for parsing multipart/form-data
const app = express();
app.use(cors());
app.use(bodyParser.json());
morganConfig(app);
app.get("/initializeUserData/:uid", upload.array(), async function(req, res) {
let result = await lib.initializeUserData(req.params.uid);
return res.status(200).send({
...result,
});
});
app.get("/getUserData/:uid", async function(req, res) {
let result = await lib.getUserData(req.params.uid, req.query);
return res.status(200).send(result);
});
app.post("/updateUserData/:uid", upload.array(), async function(req, res) {
let result = await lib.updateUserData(req.params.uid, req.body);
return res.status(200).send({
...result,
});
});
app.put("/updatePrograms/:uid", upload.array(), async function(req, res) {
let result = await lib.updatePrograms(req.params.uid, req.body);
return res.status(200).send({
...result,
});
});
app.post("/createProgram", upload.array(), async function(req, res) {
let result = await lib.createProgram(req.body || {});
return res.status(200).send({
...result,
});
});
app.post("/deleteProgram", upload.array(), async function(req, res) {
let result = await lib.deleteProgram(req.body || {});
return res.status(200).send({
...result,
});
});
app.get("/getProgram/:docid", upload.array(), async function(req, res) {
let result = await lib.getProgram(req.params.docid);
return res.status(200).send({
...result,
});
});
// Start the server
const PORT = process.env.PORT || 8081;
app.listen(PORT, () => {
winston.info(`App listening on port ${PORT}`);
winston.info("Press Ctrl+C to quit.");
});