From e4e55ca974c1fd64dc78a62d37b92485b51e24a1 Mon Sep 17 00:00:00 2001
From: Federico Hurtado <fed_home@Federicos-Mac-mini.local>
Date: Wed, 23 Oct 2024 08:49:33 -0400
Subject: [PATCH] contact and degree repository to save data to db.

---
 backend/repository/contactRepository.js | 36 +++++++++++++++++++++++++
 backend/repository/degreeRepository.js  |  2 +-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/backend/repository/contactRepository.js b/backend/repository/contactRepository.js
index e69de29..b096cb2 100644
--- a/backend/repository/contactRepository.js
+++ b/backend/repository/contactRepository.js
@@ -0,0 +1,36 @@
+const { pool } = require("../config/database/database.config");
+// contacts: [
+//     {
+//         contactNumber: string --> i guess this can be a phone nunber, email, etc.
+//         contactType: string --> need to define list: phone, email, ....
+//         preferredContact: boolean
+//     },
+
+async function addContact(contact, peopleId) {
+  // extract the parts of the contact
+  let { contactNumber, contactType, preferredContact } = contact;
+
+  console.log("adding contact....");
+
+  try {
+    // query for adding the contact
+    const query = `
+        INSERT INTO peopleContact (peopleId, contactNumber, contactType, preferredContact)
+        VALUES (?,?,?,?)
+    `;
+
+    // insert data into db
+    const [results] = await pool.query(query, [
+      peopleId,
+      contactNumber,
+      contactType,
+      preferredContact,
+    ]);
+
+    return results;
+  } catch (error) {
+    console.log(error);
+  }
+}
+
+module.exports = { addContact };
diff --git a/backend/repository/degreeRepository.js b/backend/repository/degreeRepository.js
index d36e65f..9955b1d 100644
--- a/backend/repository/degreeRepository.js
+++ b/backend/repository/degreeRepository.js
@@ -14,7 +14,7 @@ async function addDegree(degree, peopleId) {
 
   try {
     // Use the helper function to determine the degreeTypeId
-    degreeTypeId = await _lookupDegreeTypeId(degreeType);
+    let degreeTypeId = await _lookupDegreeTypeId(degreeType);
 
     const query = `
         INSERT INTO peopleDegree (peopleId, degreeTypeId, degreeDepartment, degreeCollege, degreeYear, degreeDescription)
-- 
GitLab