Skip to content

Commit

Permalink
Merge branch 'main' into feature/IBS-11
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuamenezes authored Jun 16, 2023
2 parents f5d69b5 + 6de26d3 commit b1564ff
Show file tree
Hide file tree
Showing 23 changed files with 3,120 additions and 1,309 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ jobs:
run: |
echo "${{ secrets.FRONTEND_ENV }}" > ./frontend/.env;
echo "${{ secrets.BACKEND_ENV }}" > ./backend/.env;
- name: Rootless Docker
uses: ScribeMD/rootless-docker@0.2.2

- name: compose build
run: docker compose build

Expand Down
402 changes: 246 additions & 156 deletions backend/module/course/admin/add.js

Large diffs are not rendered by default.

51 changes: 33 additions & 18 deletions backend/module/task/staff/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const router = express.Router();
const client = require("../../../setup/db");
const helpers = require("../../../utilities/helpers");

router.post("/", (req, res) => {
router.post("/", async (req, res) => {
if (!("task" in req.body) || helpers.name_validate(req.body["task"])) {
res.status(400).json({ message: "The task is missing or invalid." });
return;
Expand All @@ -17,6 +17,26 @@ router.post("/", (req, res) => {
.json({ message: "The due date is missing or not correct." });
return;
}
if (!("weight" in req.body) || helpers.number_validate(req.body["weight"])) {
res
.status(400)
.json({ message: "The weight property is missing or invalid." });
return;
}
let isWeightExceeded = await helpers.weight_validate(
typeof req.body["weight"] === "string"
? parseInt(req.body["weight"])
: req.body["weight"],
res.locals["course_id"]
);

if (isWeightExceeded) {
res
.status(400)
.json({ message: "The accumulated weight of all tasks exceeds 100" });
return;
}

if (!("hidden" in req.body) || helpers.boolean_validate(req.body["hidden"])) {
res
.status(400)
Expand Down Expand Up @@ -48,22 +68,18 @@ router.post("/", (req, res) => {
!("hide_interview" in req.body) ||
helpers.boolean_validate(req.body["hide_interview"])
) {
res
.status(400)
.json({
message: "The hide interview property is missing or not correct.",
});
res.status(400).json({
message: "The hide interview property is missing or not correct.",
});
return;
}
if (
!("change_group" in req.body) ||
helpers.boolean_validate(req.body["change_group"])
) {
res
.status(400)
.json({
message: "The change group property is missing or not correct.",
});
res.status(400).json({
message: "The change group property is missing or not correct.",
});
return;
}

Expand Down Expand Up @@ -93,12 +109,10 @@ router.post("/", (req, res) => {
helpers.string_validate(req.body["starter_code_url"]) ||
!req.body["starter_code_url"].includes(".git")
) {
res
.status(400)
.json({
message:
"The starter code url is invalid. It should start with https:// and end with .git",
});
res.status(400).json({
message:
"The starter code url is invalid. It should start with https:// and end with .git",
});
return;
} else {
starter_code_url = req.body["starter_code_url"];
Expand All @@ -109,10 +123,11 @@ router.post("/", (req, res) => {
let sql_add =
"INSERT INTO course_" +
res.locals["course_id"] +
".task (task, due_date, hidden, min_member, max_member, max_token, change_group, hide_interview, interview_group, task_group_id, starter_code_url, long_name) VALUES (($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12))";
".task (task, due_date, weight, hidden, min_member, max_member, max_token, change_group, hide_interview, interview_group, task_group_id, starter_code_url, long_name) VALUES (($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13))";
let sql_add_data = [
req.body["task"],
due_date,
req.body["weight"],
req.body["hidden"],
req.body["min_member"],
req.body["max_member"],
Expand Down
21 changes: 12 additions & 9 deletions backend/module/task/staff/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ const router = express.Router();
const client = require("../../../setup/db");

router.get("/", (req, res) => {
let sql_task = "SELECT task, to_char(due_date AT TIME ZONE 'America/Toronto', 'YYYY-MM-DD HH24:MI:SS') AS due_date, hidden, min_member, max_member, max_token, change_group, hide_interview, interview_group, task_group_id, starter_code_url FROM course_" + res.locals["course_id"] + ".task ORDER BY due_date, task";
client.query(sql_task, [], (err, pg_res) => {
if (err) {
res.status(404).json({ message: "Unknown error." });
} else {
res.status(200).json({ count: pg_res.rowCount, task: pg_res.rows });
}
});
})
let sql_task =
"SELECT task, to_char(due_date AT TIME ZONE 'America/Toronto', 'YYYY-MM-DD HH24:MI:SS') AS due_date, weight, hidden, min_member, max_member, max_token, change_group, hide_interview, interview_group, task_group_id, starter_code_url FROM course_" +
res.locals["course_id"] +
".task ORDER BY due_date, task";
client.query(sql_task, [], (err, pg_res) => {
if (err) {
res.status(404).json({ message: "Unknown error." });
} else {
res.status(200).json({ count: pg_res.rowCount, task: pg_res.rows });
}
});
});

module.exports = router;
228 changes: 146 additions & 82 deletions backend/module/task/staff/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,158 @@ const router = express.Router();
const client = require("../../../setup/db");
const helpers = require("../../../utilities/helpers");

router.put("/", (req, res) => {
if (res.locals["task"] === "") {
res.status(400).json({ message: "The task is missing or invalid." });
return;
}
if (!("due_date" in req.body) || helpers.time_validate(req.body["due_date"])) {
res.status(400).json({ message: "The due date is missing or not correct." });
return;
}
if (!("hidden" in req.body) || helpers.boolean_validate(req.body["hidden"])) {
res.status(400).json({ message: "The hidden property is missing or not correct." });
return;
}
if (!("min_member" in req.body) || helpers.number_validate(req.body["min_member"])) {
res.status(400).json({ message: "The min member is missing or invalid." });
return;
}
if (!("max_member" in req.body) || helpers.number_validate(req.body["max_member"])) {
res.status(400).json({ message: "The max member is missing or invalid." });
return;
}
if (!("max_token" in req.body) || helpers.number_validate(req.body["max_token"])) {
res.status(400).json({ message: "The max token is missing or invalid." });
return;
}
if (!("hide_interview" in req.body) || helpers.boolean_validate(req.body["hide_interview"])) {
res.status(400).json({ message: "The hide interview property is missing or not correct." });
return;
}
if (!("change_group" in req.body) || helpers.boolean_validate(req.body["change_group"])) {
res.status(400).json({ message: "The change group property is missing or not correct." });
return;
}
router.put("/", async (req, res) => {
if (res.locals["task"] === "") {
res.status(400).json({ message: "The task is missing or invalid." });
return;
}
if (
!("due_date" in req.body) ||
helpers.time_validate(req.body["due_date"])
) {
res
.status(400)
.json({ message: "The due date is missing or not correct." });
return;
}
if (!("weight" in req.body) || helpers.number_validate(req.body["weight"])) {
res
.status(400)
.json({ message: "The weight property is missing or invalid." });
return;
}
let isWeightExceeded = await helpers.weight_validate(
typeof req.body["weight"] === "string"
? parseInt(req.body["weight"])
: req.body["weight"],
res.locals["course_id"]
);

if (isWeightExceeded) {
res
.status(400)
.json({ message: "The accumulated weight of all tasks exceeds 100" });
return;
}

let interview_group = null;
if ("interview_group" in req.body) {
if (req.body["interview_group"] === "") {
interview_group = null;
} else if (helpers.name_validate(req.body["interview_group"])) {
res.status(400).json({ message: "The interview group is invalid." });
return;
} else {
interview_group = req.body["interview_group"];
}
if (!("hidden" in req.body) || helpers.boolean_validate(req.body["hidden"])) {
res
.status(400)
.json({ message: "The hidden property is missing or not correct." });
return;
}
if (
!("min_member" in req.body) ||
helpers.number_validate(req.body["min_member"])
) {
res.status(400).json({ message: "The min member is missing or invalid." });
return;
}
if (
!("max_member" in req.body) ||
helpers.number_validate(req.body["max_member"])
) {
res.status(400).json({ message: "The max member is missing or invalid." });
return;
}
if (
!("max_token" in req.body) ||
helpers.number_validate(req.body["max_token"])
) {
res.status(400).json({ message: "The max token is missing or invalid." });
return;
}
if (
!("hide_interview" in req.body) ||
helpers.boolean_validate(req.body["hide_interview"])
) {
res.status(400).json({
message: "The hide interview property is missing or not correct.",
});
return;
}
if (
!("change_group" in req.body) ||
helpers.boolean_validate(req.body["change_group"])
) {
res.status(400).json({
message: "The change group property is missing or not correct.",
});
return;
}

let interview_group = null;
if ("interview_group" in req.body) {
if (req.body["interview_group"] === "") {
interview_group = null;
} else if (helpers.name_validate(req.body["interview_group"])) {
res.status(400).json({ message: "The interview group is invalid." });
return;
} else {
interview_group = req.body["interview_group"];
}
}

let task_group_id = null;
if ("task_group_id" in req.body) {
if (req.body["task_group_id"] === "") {
task_group_id = null;
} else if (helpers.number_validate(req.body["task_group_id"])) {
res.status(400).json({ message: "The task group id is invalid." });
return;
} else {
task_group_id = req.body["task_group_id"];
}
let task_group_id = null;
if ("task_group_id" in req.body) {
if (req.body["task_group_id"] === "") {
task_group_id = null;
} else if (helpers.number_validate(req.body["task_group_id"])) {
res.status(400).json({ message: "The task group id is invalid." });
return;
} else {
task_group_id = req.body["task_group_id"];
}
}

let starter_code_url = null;
if ("starter_code_url" in req.body) {
if (req.body["starter_code_url"] === "") {
starter_code_url = null;
} else if (helpers.string_validate(req.body["starter_code_url"])) {
res.status(400).json({ message: "The starter code url is invalid." });
return;
} else {
starter_code_url = req.body["starter_code_url"];
}
let starter_code_url = null;
if ("starter_code_url" in req.body) {
if (req.body["starter_code_url"] === "") {
starter_code_url = null;
} else if (helpers.string_validate(req.body["starter_code_url"])) {
res.status(400).json({ message: "The starter code url is invalid." });
return;
} else {
starter_code_url = req.body["starter_code_url"];
}
}

let due_date = req.body["due_date"] + " America/Toronto";
let sql_update = "UPDATE course_" + res.locals["course_id"] + ".task SET due_date = ($1), hidden = ($2), min_member = ($3), max_member = ($4) , max_token = ($5), change_group = ($6), hide_interview = ($7), interview_group = ($8), task_group_id = ($9), starter_code_url = ($10) WHERE task = ($11)";
let sql_update_data = [due_date, req.body["hidden"], req.body["min_member"], req.body["max_member"], req.body["max_token"], req.body["change_group"], req.body["hide_interview"], interview_group, task_group_id, starter_code_url, res.locals["task"]];
let due_date = req.body["due_date"] + " America/Toronto";
let sql_update =
"UPDATE course_" +
res.locals["course_id"] +
".task SET due_date = ($1), hidden = ($2), min_member = ($3), max_member = ($4) , max_token = ($5), change_group = ($6), hide_interview = ($7), interview_group = ($8), task_group_id = ($9), starter_code_url = ($10), weight = ($11) WHERE task = ($12)";
let sql_update_data = [
due_date,
req.body["hidden"],
req.body["min_member"],
req.body["max_member"],
req.body["max_token"],
req.body["change_group"],
req.body["hide_interview"],
interview_group,
task_group_id,
starter_code_url,
req.body["weight"],
res.locals["task"],
];

client.query(sql_update, sql_update_data, (err, pg_res) => {
if (err) {
if (err.code === "23503") {
res.status(400).json({ message: "The task_group_id is not found in the database." });
} else {
res.status(404).json({ message: "Unknown error." });
console.log(err);
}
} else if (pg_res.rowCount === 0) {
res.status(400).json({ message: "The task is invalid." });
} else {
res.status(200).json({ message: "The task is changed." });
}
});
})
client.query(sql_update, sql_update_data, (err, pg_res) => {
if (err) {
if (err.code === "23503") {
res
.status(400)
.json({ message: "The task_group_id is not found in the database." });
} else {
res.status(404).json({ message: "Unknown error." });
console.log(err);
}
} else if (pg_res.rowCount === 0) {
res.status(400).json({ message: "The task is invalid." });
} else {
res.status(200).json({ message: "The task is changed." });
}
});
});

module.exports = router;
module.exports = router;
Loading

0 comments on commit b1564ff

Please sign in to comment.