Skip to content

Commit

Permalink
Merge pull request #21 from teaching-the-art-of-fp/data-coll-fix
Browse files Browse the repository at this point in the history
Data collection encoding solution fix
  • Loading branch information
hannelita authored Mar 12, 2021
2 parents ff48fff + d084574 commit 82ae88e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RUN opam install . --destdir /home/opam/install-prefix --locked
FROM alpine:3.7 as client

RUN apk update \
&& apk add ncurses-libs libev dumb-init \
&& apk add ncurses-libs libev dumb-init openssl \
&& addgroup learn-ocaml \
&& adduser learn-ocaml -DG learn-ocaml

Expand All @@ -53,7 +53,7 @@ LABEL org.opencontainers.image.vendor="The OCaml Software Foundation"
FROM alpine:3.7 as program

RUN apk update \
&& apk add ncurses-libs libev dumb-init git \
&& apk add ncurses-libs libev dumb-init git openssl \
&& addgroup learn-ocaml \
&& adduser learn-ocaml -DG learn-ocaml

Expand Down
25 changes: 11 additions & 14 deletions node/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const compile_collection = process.env.COMP_COLLECTION;
const eval_collection = process.env.EVAL_COLLECTION;
const mongoose = require('mongoose');

app.use(bodyParser.text({ type: "application/json" }));
// app.use(bodyParser.text({ type: "application/json" }));
app.use(bodyParser.json());

// connect to database
// mongoose.connect('mongodb://172.17.0.1/learn-ocaml-code');
Expand All @@ -28,10 +29,9 @@ app.post("/grade", function (req, res)
{
if (req.body)
{
const raw_array = req.body;
const split_array = raw_array.split(",");
const collection = JSON.parse(split_array[3]);
let parsedSolStr = split_array.slice(4).join(' ').slice(0, -1);
const split_array = req.body;
const collection = split_array[3];
let parsedSolStr = split_array[4];
const obj = new Object();
obj.studentId = split_array[1];
obj.timestamp = new Date().toString();
Expand All @@ -54,10 +54,9 @@ app.post("/compile", function (req, res)
{
if (req.body)
{
const raw_array = req.body;
const split_array = raw_array.split(",");
const collection = JSON.parse(split_array[3]);
let parsedSolStr = split_array.slice(4).join(' ').slice(0, -1);
const split_array = req.body;
const collection = split_array[3];
let parsedSolStr = split_array[4];
const obj = new Object();
obj.studentId = split_array[1];
obj.timestamp = new Date().toString();
Expand All @@ -78,15 +77,13 @@ app.post("/eval", function (req, res)
{
if (req.body)
{
const raw_array = req.body;
const split_array = raw_array.split(",");
const collection = JSON.parse(split_array[3]);
const parsedSolStr = split_array.slice(4).join(' ').slice(0, -1);
const split_array = req.body;
const collection = split_array[3];
let parsedSolStr = split_array[4];
const obj = new Object();
obj.studentId = split_array[1];
obj.timestamp = new Date().toString();
obj.solution = parsedSolStr;

const jsonString = JSON.stringify(obj);
const solution = JSON.parse( jsonString ); // parse req.body as an object
db.collection(collection).insertOne(solution);
Expand Down

0 comments on commit 82ae88e

Please sign in to comment.