From e3a25ede59f9eae8f922e9dd070873d452b69ff8 Mon Sep 17 00:00:00 2001 From: Argiris Deligiannidis Date: Mon, 15 Apr 2024 02:14:55 +0300 Subject: [PATCH] PK index fixes --- components/WeatherModals/AddLocation.vue | 14 ++++++++---- components/WeatherModals/DeleteLocation.vue | 24 ++++++++++----------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/components/WeatherModals/AddLocation.vue b/components/WeatherModals/AddLocation.vue index fcbb8bb..e3235b3 100644 --- a/components/WeatherModals/AddLocation.vue +++ b/components/WeatherModals/AddLocation.vue @@ -59,7 +59,7 @@ export default defineNuxtComponent({ this.apiURL = `${this.apiBaseURL}/locations`; if (input) { await this.getDatabaseLocations(true); - let idx = 0; + var idx = 0; for (let i = 0; i < this.cmpDatabaseLocations.length; i++) { if ( this.databaseLocations[i]['name'].includes(input.name) && @@ -88,11 +88,16 @@ export default defineNuxtComponent({ }); this.closeModal('add'); } else { - idx = this.databaseLocations.length + 1; + idx = 0; + for (let i = 0; i < this.databaseLocations.length; i++) { + if (this.databaseLocations[i]['id'] > idx) { + idx = this.databaseLocations[i]['id']; + } + } await $fetch(this.apiURL, { method: 'POST', body: JSON.stringify({ - id: idx, + id: idx + 1, name: input.name, country: input.country, longitude: input.longitude, @@ -100,7 +105,8 @@ export default defineNuxtComponent({ user: this.userId, }), }); - this.fetchWeatherData(false, idx); + await this.addNewLocID(idx + 1); + await this.fetchWeatherData(false, idx + 1); this.displayNotification('add', input); this.closeModal('add'); } diff --git a/components/WeatherModals/DeleteLocation.vue b/components/WeatherModals/DeleteLocation.vue index 52784e6..9fd0807 100644 --- a/components/WeatherModals/DeleteLocation.vue +++ b/components/WeatherModals/DeleteLocation.vue @@ -49,19 +49,17 @@ export default defineNuxtComponent({ await this.removeLocID(input); await delete this.weatherData[input]; - if (this.deleteBootstrapData == true) { - await fetch(`${this.apiBaseURL}/locations/${input}`, { - method: 'DELETE', - body: JSON.stringify({ - id: input, - user: this.userId, - }), - }) - .then((res) => res.json()) - .then(async (json) => { - console.log('Deleted: ' + input); - }); - } + await fetch(`${this.apiBaseURL}/locations/${input}`, { + method: 'DELETE', + body: JSON.stringify({ + id: input, + }), + }) + .then((res) => res.json()) + .then(async (json) => { + console.log('Deleted: ' + input); + }); + this.apiURL = ''; await this.getDatabaseLocations(); },