diff --git a/login.html b/public/login.html
similarity index 96%
rename from login.html
rename to public/login.html
index e05fbde..3272368 100644
--- a/login.html
+++ b/public/login.html
@@ -1,145 +1,145 @@
-
-
-
-
-
-
Log in • Study-Better
-
-
-
-
-
-
- Please log in to continue
-
-
-
-
-
-
-
+
+
+
+
+
+
Log in • Study-Better
+
+
+
+
+
+
+ Please log in to continue
+
+
+
+
+
+
+
diff --git a/mybets.html b/public/mybets.html
similarity index 100%
rename from mybets.html
rename to public/mybets.html
diff --git a/script.js b/public/script.js
similarity index 86%
rename from script.js
rename to public/script.js
index a0eac25..435b972 100644
--- a/script.js
+++ b/public/script.js
@@ -135,7 +135,8 @@ function getBetsForCurrentUser() {
return bets.filter((b) => b.betterId === currentUser.id);
}
-function fillFromGroup(betsIndex = 0) {
+// faculty is a text input
+function fillFromGroup(faculty) {
if (!bets.length) {
console.warn("No bets available yet.");
return;
@@ -144,12 +145,19 @@ function fillFromGroup(betsIndex = 0) {
const container = document.getElementById("teams");
container.innerHTML = ""; // clear old stuff
- bets.forEach(bet => {
- const s1 = getStudentById(bets.sid1);
- const s2 = getStudentById(bets.sid2);
+ const filteredBets = bets.filter(bet => bet.faculty.toLowerCase() === 'fas'); // hardcoded for now
+ if (!filteredBets.length) {
+ container.innerHTML = `
No bets available for faculty: ${faculty}
`;
+ return;
+ }
+
+
+ filteredBets.forEach(bet => {
+ const s1 = getStudentById(bet.sid1);
+ const s2 = getStudentById(bet.sid2);
if (!s1 || !s2) {
- console.warn("Missing student for group", group.id);
+ console.warn("Missing student for the bet", bet.id);
return;
}
@@ -160,11 +168,11 @@ function fillFromGroup(betsIndex = 0) {
${s1.first_name} ${s1.last_name} – ${bet.desc1}
vs
-
${s2.first_name} ${s2.last_name} – ${group.desc2}
+
${s2.first_name} ${s2.last_name} – ${bet.desc2}
-
-
+
+
`;
diff --git a/server.js b/server.js
index 392b548..ab838ff 100644
--- a/server.js
+++ b/server.js
@@ -1,4 +1,6 @@
const http = require("http");
+const fs = require("fs");
+const path = require("path");
const { Pool } = require("pg");
// connection pool to the PostgreSQL database
@@ -10,6 +12,44 @@ const pool = new Pool({
// Create HTTP server
const server = http.createServer(async (req, res) => {
try{
+
+ if (req.url === "/") {
+ const filePath = path.join(__dirname, "public", "index.html");
+ fs.readFile(filePath, (err, content) => {
+ if (err) {
+ res.writeHead(500);
+ res.end("Error loading index.html");
+ } else {
+ res.writeHead(200, { "Content-Type": "text/html" });
+ res.end(content);
+ }
+ });
+ return;
+ }
+
+ if (req.url.endsWith(".js") || req.url.endsWith(".css")) {
+ const filePath = path.join(__dirname, "public", req.url);
+ fs.readFile(filePath, (err, content) => {
+ if (err) {
+ res.writeHead(404);
+ res.end("File not found");
+ } else {
+ const ext = path.extname(filePath);
+ const type =
+ ext === ".js"
+ ? "text/javascript"
+ : ext === ".css"
+ ? "text/css"
+ : "text/plain";
+ res.writeHead(200, { "Content-Type": type });
+ res.end(content);
+ }
+ });
+ return;
+ }
+
+ // ----------------------------
+
// Get all betters
if (req.url === "/better" && req.method === "GET") {
const result = await pool.query("SELECT * FROM better");