From 04726443dce96f4b41f3506a2e6570db52b944ef Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Tue, 25 Oct 2022 19:30:56 +0300 Subject: Fixed bugs from last commit --- dbparse.js | 29 +++++++++++++++++++++-------- server.js | 11 ++++++++++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/dbparse.js b/dbparse.js index f196c78..0f029b4 100644 --- a/dbparse.js +++ b/dbparse.js @@ -117,25 +117,38 @@ async function writeShift(weekday, shiftId, shiftLine, courseLine, DB) const teacher = course[3] || null; // Get the class - let className = await DB.execute( + let className1 = await DB.execute( "SELECT class FROM classes WHERE course=?", - [courseName] + [courseName1] ); - if (className !== undefined) - className = className.class; + className1 = className1[0]; + if (className1 !== undefined) + className1 = className1.class; else - className = null; - className = className[0]; + className1 = null; + + let className2 = undefined; + if (courseName2 !== undefined) { + className2 = await DB.execute( + "SELECT class FROM classes WHERE course=?", + [courseName2] + ); + className2 = className2[0]; + if (className2 !== undefined) + className2 = className2.class; + else + className2 = null; + } // Add the info dbOperations.push(DB.execute( `INSERT IGNORE INTO shifts VALUES (${weekday}, ${shiftId}, ?, ?, ?)`, - [courseName1, teacher, className] + [courseName1, teacher, className1] )); if (courseName2 !== null) { dbOperations.push(DB.execute( `INSERT IGNORE INTO shifts VALUES (${weekday}, ${shiftId}, ?, ?, ?)`, - [courseName2, teacher, className] + [courseName2, teacher, className2] )); } } diff --git a/server.js b/server.js index 5b51eee..11c50bd 100644 --- a/server.js +++ b/server.js @@ -207,13 +207,22 @@ async function buildMain(args) if (res["shift"] === undefined) { let shift = await DBPARSE.get(day, index, SQLDB); + // shift looks like the following: (useful info for debugging. this is really obscure without any information about how this variable looks like.) + /*[ + { + name: 'RUOKAILUVUORO I: ruokailu klo 10.50 – 11.20, oppitunti klo 11.30 – 12.50' + }, + [ { course: 'OPO15', teacher: null, class: null } ] + ]*/ if (shift !== undefined) { res["shift"] = shift[0].name; res["shift-header"] = ""; for (let i = 0; i < shift[1].length; i++) { - res["shift-header"] += `${shift[1][i].course}/${shift[1][i].teacher}`; + res["shift-header"] += `${shift[1][i].course}`; + if (shift[1][i].teacher !== null) + res["shift-header"] += `/${shift[1][i].teacher}`; if (shift[1][i].class !== null) res["shift-header"] += `/${shift[1][i].class}` if (i + 1 !== shift[1].length) -- cgit v1.2.3