Skip to content
Snippets Groups Projects

able to add invovlvements and chapters if they are not initially in the lookup table

Merged fhurtado14 requested to merge feature/create-new-lookup-items into main
4 files
+ 53
38
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -69,8 +69,21 @@ async function getChapterId(name) {
console.log("Found chapter id: ", rows[0]);
return rows[0].chapterId;
} else {
console.log("Chapter not id found: ", name);
return null;
console.log("Chapter not id found, creating new chapter");
// Add the chapter if it doesn't exist
const insertQuery = "INSERT INTO chapterLookup (name) VALUES (?)";
const [insertResult] = await pool.query(insertQuery, [name]);
if (insertResult.insertId) {
console.log(
"Successfully created chapter with ID: ",
insertResult.insertId
);
return insertResult.insertId;
} else {
console.error("Error: Chapter creation did not return an ID.");
throw new Error("Failed to create chapter.");
}
}
} catch (error) {
console.error(`Error fetching chapter with name ${name}:`, error);
Loading