Skip to content

Commit 6d03fc1

Browse files
committed
retrieve trial choices from mongodb and refactor routes
relates to #8
1 parent 6642c63 commit 6d03fc1

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

server/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const bodyParser = require("body-parser");
77

88
const app = express();
99

10-
const routes = require("./queries/binary");
10+
const routes = require("./routes.js");
1111

1212
app.use(bodyParser.json());
1313
require("env2")("./config.env");

server/queries/binary.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
const mongoose = require("mongoose");
2-
const router = require("express").Router();
32

43
mongoose.connect(process.env.DATABASE_URL);
54
const { connection } = mongoose;
6-
router.post("/trial_form", (req, res) => {
5+
exports.post = (req, res) => {
76
console.log("bodyyyyyyyy: ", req.body);
87
req.body.timestamp = new Date();
98
connection.collection("trialsData").insert(req.body);
109
res.send("hello");
11-
});
12-
13-
module.exports = router;
10+
};

server/queries/get_choices.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const mongoose = require("mongoose");
2+
3+
mongoose.connect(process.env.DATABASE_URL);
4+
const { connection } = mongoose;
5+
exports.get = (req, res) => {
6+
console.log(req.params.trialId);
7+
console.log("hello");
8+
connection
9+
.collection("trialsData")
10+
.findOne({ trialId: `${req.params.trialId}` }, (err, obj) => {
11+
res.send(obj.choices);
12+
});
13+
};

server/routes.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const router = require("express").Router();
2+
3+
const binary = require("./queries/binary");
4+
const get_choices = require("./queries/get_choices");
5+
6+
router.post("/trial_form", binary.post);
7+
router.get("/choices/:trialId", get_choices.get);
8+
9+
module.exports = router;

0 commit comments

Comments
 (0)