HyeonJun Jeon

[Add] Schedule type

......@@ -15,6 +15,7 @@ function jcalToSQL(jcal, userID) {
connection.connect();
const commonCols = [
"userID",
"uid",
"label",
"subjectID",
......@@ -22,27 +23,28 @@ function jcalToSQL(jcal, userID) {
"description",
"url",
"detail",
"status",
];
const dateScheCols = [...commonCols, "date"];
const timeScheCols = [...commonCols, "date", "startTime", "endTime"];
const dateQueryString =
"INSERT IGNORE INTO schedules_date (userID," +
"INSERT IGNORE INTO schedules_date (" +
dateScheCols.join(",") +
") VALUES ?";
const timeQueryString =
"INSERT IGNORE INTO schedules_time (userID," +
"INSERT IGNORE INTO schedules_time (" +
timeScheCols.join(",") +
") VALUES ?";
const dateSchedules = [];
const timeSchedules = [];
for (const sche of jcal) {
if (sche.scheType === "date") {
dateSchedules.push([userID, ...dateScheCols.map((col) => sche[col])]);
} else if (sche.scheType === "time") {
timeSchedules.push([userID, ...timeScheCols.map((col) => sche[col])]);
} else console.log("unexpected scheType", sche);
sche.userID = userID;
sche.type = "assignment";
if (sche.scheType === "date")
dateSchedules.push(dateScheCols.map((col) => sche[col]));
else if (sche.scheType === "time")
timeSchedules.push(timeScheCols.map((col) => sche[col]));
else console.log("unexpected scheType", sche);
}
connection.query(dateQueryString, [dateSchedules], (error, result) => {
......