diff options
| -rw-r--r-- | dbparse.js | 29 | ||||
| -rw-r--r-- | server.js | 11 | 
2 files changed, 31 insertions, 9 deletions
@@ -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]  			));  		}  	} @@ -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)  | 
