Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

149 database log user input #186

Merged
merged 2 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const QuestionsHandler = (props) => {
*/
function onComplete() {
console.log("completed", selectedAnswers);
handleContinue();
handleContinue(selectedAnswers);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useEffect } from "react";
import { navigate } from "@reach/router";
import { EXERCISE_PLAYING } from "../../../../../constants/lab6";
import QuestionsHandler from "../../components/QuestionsHandler";
import ExerciseService from "../../../../../services/lab6/ExerciseService";

const AIAnalysisQuestions = (props) => {
const { actions } = props;
Expand All @@ -12,14 +13,9 @@ const AIAnalysisQuestions = (props) => {
actions.updateState(EXERCISE_PLAYING);
}, [actions]);

function checkValue(e) {
var value = e.target.value;
console.log("You selected " + value);
}

//changed so it doesn't skip phase 2
const handleContinue = () => {
navigate("/Lab6/Exercise/EmployerStart"); //How should we handle this (positive or negative)
const handleContinue = (answers) => {
ExerciseService.submitAIAnalysisQuestion(Array.from(answers[0]));
navigate("/Lab6/Exercise/EmployerStart");
};

const aiAnalysisData = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useEffect, useState } from "react";
import { navigate } from "@reach/router";
import { EXERCISE_PLAYING } from "../../../../../constants/lab6";
import GridImages from "../../../../body/lab/GridImages/GridImages";
import ExerciseService from "../../../../../services/lab6/ExerciseService";

const AvatarSelection = (props) => {
const { actions } = props;
Expand All @@ -15,7 +16,10 @@ const AvatarSelection = (props) => {
}, [actions]);

const confirmSelection = () => {
navigate("/Lab6/Exercise/QualificationQuestions");
if (avatar.length != 0) {
ExerciseService.submitAvatar(avatar);
navigate("/Lab6/Exercise/QualificationQuestions");
}
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable no-undef */
/* eslint-disable react/prop-types */
/* eslint-disable no-unused-vars */
import React, { useEffect, useState } from "react";
import React, { useEffect } from "react";
import { navigate } from "@reach/router";
import { EXERCISE_PLAYING } from "../../../../../constants/lab6";
import QuestionsHandler from "../../components/QuestionsHandler";
import ExerciseService from "../../../../../services/lab6/ExerciseService";

function QualificationQuestions(props) {
const { actions } = props;
Expand All @@ -13,7 +14,8 @@ function QualificationQuestions(props) {
actions.updateState(EXERCISE_PLAYING);
}, [actions]);

const handleContinue = () => {
const handleContinue = (answers) => {
ExerciseService.submitQualQuestions(answers);
navigate("/Lab6/Exercise/AnalyzeData");
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useEffect } from "react";
import { navigate } from "@reach/router";
import { EXERCISE_PLAYING } from "../../../../../constants/lab6";
import QuestionsHandler from "../../components/QuestionsHandler";
import ExerciseService from "../../../../../services/lab6/ExerciseService";

const AIReasoningQuestions = (props) => {
const { actions } = props;
Expand All @@ -11,7 +12,8 @@ const AIReasoningQuestions = (props) => {
actions.updateState(EXERCISE_PLAYING);
}, [actions]);

const handleContinue = () => {
const handleContinue = (answers) => {
ExerciseService.submitAIReasoningQuestion(Array.from(answers[0]));
navigate("/Lab6/Exercise/AIReasoning");
};
const aiReasoningData = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import { useEffect, useState } from "react";
import { EXERCISE_PLAYING } from "../../../../../constants/lab6";
import GridApplicants from "../../components/GridApplicants";
import { Modal, ModalBody, ModalFooter, Button } from "reactstrap";

//need to make sure that only when the AI doesn't recommend them and that when they are selected that the modal appears
//modal doesn't appear for the last hiring candidate selection; needs to
//need to make the bias against the glasses editable, so that when someone edits the table later the bias can change here as well
import ExerciseService from "../../../../../services/lab6/ExerciseService";

const HiringCandidate = (props) => {
//added avatar and accessoriestype modeled after bias.jsx
const { actions, avatar, accessoriesType, biasType } = props;
const { actions } = props;

const [roundOfApplicants, setRoundOfApplicants] = useState(0);

Expand All @@ -35,7 +31,7 @@ const HiringCandidate = (props) => {
answers.push(selection);
setAnswers(answers);
if (roundOfApplicants > 2) {
console.log(userAnswers);
ExerciseService.submitHiredCanidates(answers);
navigate("/Lab6/Exercise/AIReasoningQuestions");
} else {
setRoundOfApplicants(roundCount + 1);
Expand Down Expand Up @@ -65,6 +61,7 @@ const HiringCandidate = (props) => {
setAnswers(answers);
if (roundOfApplicants > 2) {
console.log(userAnswers);
ExerciseService.submitHiredCanidates(answers);
navigate("/Lab6/Exercise/AIReasoningQuestions");
} else {
let roundCount = roundOfApplicants;
Expand Down
65 changes: 65 additions & 0 deletions client/src/services/lab6/ExerciseService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* eslint-disable no-undef */
import API from "../API";

const endpoints = {
SUBMIT_AVATAR: "/lab6/exercise/avatar",
SUBMIT_QUAL_QUESTIONS: "/lab6/exercise/qualquestions",
SUBMIT_AI_ANALYSIS_QUESTION: "/lab6/exercise/aianalysisquestion",
SUBMIT_HIRED_CANIDATES: "/lab6/exercise/hiredcanidates",
SUBMIT_AI_REASONING_QUESTIONS: "/lab6/exercise/aireasoningquestion",
SUBMIT_FIXED_HIRED_CANIDATES: "/lab6/exercise/fixedhiredcanidates",
};

const ExerciseService = {
submitAvatar: (avatar) => {
return API.postWithBody(
process.env.REACT_APP_SERVER_URL + endpoints.SUBMIT_AVATAR,
{
avatar,
}
);
},
submitQualQuestions: (qualQuestions) => {
return API.postWithBody(
process.env.REACT_APP_SERVER_URL + endpoints.SUBMIT_QUAL_QUESTIONS,
{
qualQuestions,
}
);
},
submitAIAnalysisQuestion: (aiAnalysisQuestion) => {
return API.postWithBody(
process.env.REACT_APP_SERVER_URL + endpoints.SUBMIT_AI_ANALYSIS_QUESTION,
{
aiAnalysisQuestion,
}
);
},
submitHiredCanidates: (hiredCanidates) => {
return API.postWithBody(
process.env.REACT_APP_SERVER_URL + endpoints.SUBMIT_HIRED_CANIDATES,
{
hiredCanidates,
}
);
},
submitAIReasoningQuestion: (aiReasoningQuestion) => {
return API.postWithBody(
process.env.REACT_APP_SERVER_URL +
endpoints.SUBMIT_AI_REASONING_QUESTIONS,
{
aiReasoningQuestion,
}
);
},
submitFixedHiredCanidates: (fixedHiredCanidates) => {
return API.postWithBody(
process.env.REACT_APP_SERVER_URL + endpoints.SUBMIT_FIXED_HIRED_CANIDATES,
{
fixedHiredCanidates,
}
);
},
};

export default ExerciseService;
20 changes: 20 additions & 0 deletions client/src/services/lab6/RepairService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable no-undef */
import API from "../API";

const endpoints = {
SUBMIT_REPAIR: "/lab5/repair/submit",
};

const RepairService = {
submitRepair: (activity, repair) => {
return API.postWithBody(
process.env.REACT_APP_SERVER_URL + endpoints.SUBMIT_REPAIR,
{
activity,
repair,
}
);
},
};

export default RepairService;
61 changes: 61 additions & 0 deletions server/controllers/lab6/ExerciseController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const ExerciseService = require('../../services/lab6/ExerciseService');

exports.submitAvatar = (req, res) => {
ExerciseService.submitAvatar({
usersessionid: req.session.token,
avatar: req.body.avatar,
}).then((id) => {
req.session.exercise = id;
res.sendStatus(200);
});
};

exports.submitQualQuestions = (req, res) => {
ExerciseService.submitQualQuestions({
usersessionid: req.session.token,
qualQuestions: req.body.qualQuestions,
}).then((id) => {
req.session.exercise = id;
res.sendStatus(200);
});
};

exports.submitAIanalysisQuestion = (req, res) => {
ExerciseService.submitAIAnalysisQuestion({
usersessionid: req.session.token,
aiAnalysisQuestion: req.body.aiAnalysisQuestion,
}).then((id) => {
req.session.exercise = id;
res.sendStatus(200);
});
};

exports.submitHiredCanidates = (req, res) => {
ExerciseService.submitHiredCanidates({
usersessionid: req.session.token,
hiredCanidates: req.body.hiredCanidates,
}).then((id) => {
req.session.exercise = id;
res.sendStatus(200);
});
};

exports.submitAIReasoningQuestion = (req, res) => {
ExerciseService.submitAIReasoningQuestion({
usersessionid: req.session.token,
aiReasoningQuestion: req.body.aiReasoningQuestion,
}).then((id) => {
req.session.exercise = id;
res.sendStatus(200);
});
};

exports.submitFixedHiredCanidates = (req, res) => {
ExerciseService.submitFixedHiredCanidates({
usersessionid: req.session.token,
fixedHiredCanidates: req.body.fixedHiredCanidates,
}).then((id) => {
req.session.exercise = id;
res.sendStatus(200);
});
};
11 changes: 11 additions & 0 deletions server/controllers/lab6/RepairController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const RepairService = require('../../services/lab5/RepairService');

exports.submitChange = (req, res) => {
RepairService.submitChange({
usersessionid: req.session.token,
activity: req.body.activity,
repair: req.body.repair,
}).then(() => {
res.sendStatus(200);
});
};
4 changes: 2 additions & 2 deletions server/database/models/lab6/Exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module.exports = (sequelize, DataTypes) => {
},
avatar: {type: DataTypes.JSON},
qualificationquestions: {type: DataTypes.JSON},
aianalysisquestion: {type: DataTypes.STRING},
aianalysisquestion: {type: DataTypes.JSON},
hiredcanidates: {type: DataTypes.JSON},
aireasoningquestion: {type: DataTypes.STRING},
aireasoningquestion: {type: DataTypes.JSON},
fixedhiredcanidates: {type: DataTypes.JSON},
},
{tableName: 'lab6_exercise'},
Expand Down
11 changes: 11 additions & 0 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const RepairControllerLab4 = require('../controllers/lab4/RepairController');
const RepairControllerLab5 = require('../controllers/lab5/RepairController');
const ExerciseControllerLab5 = require('../controllers/lab5/ExerciseController');

// LAB6 Controller
// const RepairControllerLab6 = require('../controllers/lab6/RepairController');
const ExerciseControllerLab6 = require('../controllers/lab6/ExerciseController');

// Lab Controller
const LabController = require('../controllers/LabController');

Expand Down Expand Up @@ -79,6 +83,13 @@ router.post('/lab1/exercise/round', ExerciseControllerLab1.createRound);
router.post('/lab1/exercise/choice', ExerciseControllerLab1.createChoice);
router.post('/lab1/exercise/end', ExerciseControllerLab1.updateEndExerciseScore);
router.post('/lab5/exercise/choice', ExerciseControllerLab5.submitChoice);
router.post('/lab6/exercise/avatar', ExerciseControllerLab6.submitAvatar);
router.post('/lab6/exercise/qualquestions', ExerciseControllerLab6.submitQualQuestions);
router.post('/lab6/exercise/aianalysisquestion', ExerciseControllerLab6.submitAIanalysisQuestion);
router.post('/lab6/exercise/hiredcanidates', ExerciseControllerLab6.submitHiredCanidates);
router.post('/lab6/exercise/aireasoningquestion', ExerciseControllerLab6.submitAIReasoningQuestion);
router.post('/lab6/exercise/fixedhiredcanidates', ExerciseControllerLab6.submitFixedHiredCanidates);

// Code Editor Routes
router.post('/lab1/repair/submit', RepairControllerLab1.submitChange);
router.post('/lab2/repair/submit', RepairControllerLab2.submitChange);
Expand Down
Loading