var _ = require('lodash'),
    assessmentData = require('./assessments'),
    http = require("q-io/http");

var routes = {};

routes.publish = function (router) {

    router.get('/assess/:assessmentId', function (request, response) {
        var assessmentId = request.params.assessmentId;
        var assessment = assessmentData.get(assessmentId);
        response.send(assessment);
    });

    router.post('/assess/:assessmentId', function (request, response) {
        var assessmentId = request.params.assessmentId;
        var assessment = assessmentData.get(assessmentId);
        var submittedCode = request.body.code;
        var options = {
            url: 'http://localhost:5020/v1/',
            method: 'POST',
            body: [
                JSON.stringify({
                    assessment: {
                        title: assessment.title,
                        className: assessment.className,
                        tests: assessment.tests
                    },
                    code: submittedCode
                })
            ]
        };
        http.request(http.normalizeRequest(options))
            .then(function (submissionResponse) {
                submissionResponse.body.read().then(function (body) {
                    response
                        .status(submissionResponse.status)
                        .send(body);
                });
            });
    });

};

module.exports = routes;
var _ = require('lodash'),
    assessmentData = require('./assessments'),
    http = require("q-io/http");

var routes = {};

routes.publish = function (router) {

    router.get('/assess/:assessmentId', function (request, response) {
        var assessmentId = request.params.assessmentId;
        var assessment = _.cloneDeep(assessmentData.get(assessmentId));
        delete assessment.className;
        delete assessment.tests;
        delete assessment.tips;
        delete assessment.guides;
        response.send(assessment);
    });

    router.post('/assess/:assessmentId', function (request, response) {
        var assessmentId = request.params.assessmentId;
        var assessment = assessmentData.get(assessmentId);
        var submittedCode = request.body.code;
        var options = {
            url: 'http://localhost:5020/v1/',
            method: 'POST',
            body: [
                JSON.stringify({
                    assessment: {
                        title: assessment.title,
                        className: assessment.className,
                        tests: assessment.tests
                    },
                    code: submittedCode
                })
            ]
        };
        http.request(http.normalizeRequest(options))
            .then(function (submissionResponse) {
                submissionResponse.body.read().then(function (body) {
                    response
                        .status(submissionResponse.status)
                        .send(body);
                });
            });
    });

};

module.exports = routes;
Hide data from assessment info
Hide data from assessment info
