diff --git a/functions/index.js b/functions/index.js index 01496b0..07b70f8 100644 --- a/functions/index.js +++ b/functions/index.js @@ -49,8 +49,8 @@ exports.postStationData = functions.https.onRequest((request, response) => { cors(request, response, () => { var batchWrite = db.batch(); jsonData.forEach((doc) => { - // append if the dartCodes hashset is empty or the current station is not present - if (dartCodes.size == 0 || !dartCodes.has(doc["StationCode"][0])) { + // append if the dartCodes hashset is empty or the current station is not present, and ignoring positions of zero + if ((dartCodes.size == 0 || !dartCodes.has(doc["StationCode"][0])) && !(doc["StationLongitude"] == 0 || doc["StationLatitude"] == 0)) { doc["StationType"] = [stationTypeCode] var docID = db.collection('stations').doc(doc["StationCode"][0]) batchWrite.set(docID, doc); @@ -199,13 +199,26 @@ exports.postLiveTrainData = functions.https.onRequest((request, response) => { }) }) -exports.securefunction = functions.https.onCall((data, context) => { - if (typeof context.auth === undefined) { - // user not logged in - return "User is not logged in" - } - else { - // user logged in - return "User is logged in" - } +// secure function to fetch a user's filter preferences from the database +exports.getPreferences = functions.https.onCall((data, context) => { + if (!context.auth) return "Error request is not verified" + return admin.firestore().collection('preferences').doc(context.auth.uid).get().then((preferences) => { + return preferences.data() + }) +}) + +// secure function to set a user's filter preferences in the database +exports.postPreferences = functions.https.onCall((data, context) => { + if (!context.auth) return "Error request is not verified" + return admin.firestore().collection('preferences').doc(context.auth.uid).set({data}).then(() => { + return "Successfully saved preferences" + }) }) + +// secure function to delete a user's filter preferences from the database +exports.deletePreferences = functions.https.onCall((data, context) => { + if (!context.auth) return "Error request is not verified" + return admin.firestore().collection('preferences').doc(context.auth.uid).delete().then(() => { + return "Successfully deleted preferences" + }) +}) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2321edc..f74f23d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "bootstrap": "^5.2.3", "chart.js": "^4.2.1", "firebase": "^9.17.1", + "mosha-vue-toastify": "^1.0.23", "ol": "^7.2.2", "vue": "^3.2.45", "vue-chartjs": "^5.2.0", @@ -1756,6 +1757,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/mosha-vue-toastify": { + "version": "1.0.23", + "resolved": "https://registry.npmjs.org/mosha-vue-toastify/-/mosha-vue-toastify-1.0.23.tgz", + "integrity": "sha512-K9fij3e3H+E/Lj82ISrgmyKrtM5RNmtZC/KG/KH47+oZGmzAkN/Zuz39kBdT/Mp8OxaHuIWQntEUMP+HdmK1xA==" + }, "node_modules/nanoid": { "version": "3.3.4", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", diff --git a/package.json b/package.json index 6c60e65..b7875f0 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "bootstrap": "^5.2.3", "chart.js": "^4.2.1", "firebase": "^9.17.1", + "mosha-vue-toastify": "^1.0.23", "ol": "^7.2.2", "vue": "^3.2.45", "vue-chartjs": "^5.2.0", diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index a710f33..51b0c33 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -34,6 +34,7 @@