ctucx.git: trainsearch

web based trip-planner, fork of https://cyberchaos.dev/yuka/trainsearch

commit e069de89c8f7c127c787f3cfc18cc52410fe5434
parent 9c8af971a703a99a53f3e543d0799478e5f9f72c
Author: Katja (ctucx) <git@ctu.cx>
Date: Thu, 30 Jan 2025 13:32:14 +0100

dataStorage: fix indentation
1 file changed, 60 insertions(+), 54 deletions(-)
M
src/dataStorage.js
|
114
++++++++++++++++++++++++++++++++++++++++++-------------------------------------
diff --git a/src/dataStorage.js b/src/dataStorage.js
@@ -5,6 +5,7 @@ export let db;
 const dbName = !isDevServer ? 'trainsearch' : 'trainsearch_dev';
 
 class IDBStorage {
+
 	constructor(idb) {
 		this.idb = idb;
 	}

@@ -13,58 +14,60 @@ class IDBStorage {
 		const idb = await openDB(dbName, 3, {
 			upgrade: async (db, oldVersion, newVersion, transaction) => {
 				console.log(`upgrading database from ${oldVersion} to ${newVersion}`);
+
 				let settings;
+
 				switch (oldVersion) {
-				case 0:
-					/*
-					 * in database scheme v1, the `journeys` object store stores whole searches, including journey data
-					 */
-					db.createObjectStore('journeys', {keyPath: 'slug'});
-					db.createObjectStore('journeysHistory', {autoIncrement: true});
-					db.createObjectStore('settings');
-				case 1:
-					/*
-					 * in database scheme v2, there are the following data stores:
-					 * `journey` for storing individual journeys with their refreshToken as index
-					 * `journeysOverview`t contains the search results with the `.journeys` field being an array of refreshTokens.
-					 *
-					 * in comparison to v1, there are these additional changes:
-					 * `journeys` object store is deleted.
-					 * `journeysHistory` object store is cleared/recreated.
-					 */
-
-					/* clean up old stuff */
-					db.deleteObjectStore('journeys');
-					db.deleteObjectStore('journeysHistory');
-
-					/* create new stores */
-					db.createObjectStore('journey', {keyPath: 'refreshToken'});
-					db.createObjectStore('journeysOverview', {keyPath: 'slug'});
-					db.createObjectStore('journeysHistory', {autoIncrement: true});
-				case 2:
-					settings = await transaction.objectStore('settings').get('settings');
-
-					if (settings !== undefined && settings.profile === 'vbb') {
-						settings.profile = 'db';
-					}
-
-					await transaction.objectStore('settings').put(settings, 'settings');
-				case 3:
-					settings = await transaction.objectStore('settings').get('settings');
-
-					if (settings !== undefined && settings.bikeFriendly === undefined) {
-						settings.bikeFriendly = false;
-					}
-
-					await transaction.objectStore('settings').put(settings, 'settings');
-				case 4:
-					settings = await transaction.objectStore('settings').get('settings');
-
-					if (settings !== undefined && settings.loyaltyCard === undefined) {
-						settings.loyaltyCard = 'NONE';
-					}
-
-					await transaction.objectStore('settings').put(settings, 'settings');
+					case 0:
+						/*
+						 * in database scheme v1, the `journeys` object store stores whole searches, including journey data
+						 */
+						db.createObjectStore('journeys', {keyPath: 'slug'});
+						db.createObjectStore('journeysHistory', {autoIncrement: true});
+						db.createObjectStore('settings');
+					case 1:
+						/*
+						 * in database scheme v2, there are the following data stores:
+						 * `journey` for storing individual journeys with their refreshToken as index
+						 * `journeysOverview`t contains the search results with the `.journeys` field being an array of refreshTokens.
+						 *
+						 * in comparison to v1, there are these additional changes:
+						 * `journeys` object store is deleted.
+						 * `journeysHistory` object store is cleared/recreated.
+						 */
+
+						/* clean up old stuff */
+						db.deleteObjectStore('journeys');
+						db.deleteObjectStore('journeysHistory');
+
+						/* create new stores */
+						db.createObjectStore('journey', {keyPath: 'refreshToken'});
+						db.createObjectStore('journeysOverview', {keyPath: 'slug'});
+						db.createObjectStore('journeysHistory', {autoIncrement: true});
+					case 2:
+						settings = await transaction.objectStore('settings').get('settings');
+
+						if (settings !== undefined && settings.profile === 'vbb') {
+							settings.profile = 'db';
+						}
+
+						await transaction.objectStore('settings').put(settings, 'settings');
+					case 3:
+						settings = await transaction.objectStore('settings').get('settings');
+
+						if (settings !== undefined && settings.bikeFriendly === undefined) {
+							settings.bikeFriendly = false;
+						}
+
+						await transaction.objectStore('settings').put(settings, 'settings');
+					case 4:
+						settings = await transaction.objectStore('settings').get('settings');
+
+						if (settings !== undefined && settings.loyaltyCard === undefined) {
+							settings.loyaltyCard = 'NONE';
+						}
+
+						await transaction.objectStore('settings').put(settings, 'settings');
 				}
 			},
 			blocking: async () => {

@@ -72,14 +75,16 @@ class IDBStorage {
 				location.reload();
 			},
 		});
+
 		return new IDBStorage(idb);
 	}
 
 	async addJourneys(journeyEntries, overviewEntry, historyEntry) {
-		const tx = this.idb.transaction(['journey', 'journeysOverview', 'journeysHistory'], 'readwrite');
-		const journeyStore = tx.objectStore('journey');
+		const tx                    = this.idb.transaction(['journey', 'journeysOverview', 'journeysHistory'], 'readwrite');
+		const journeyStore          = tx.objectStore('journey');
 		const journeysOverviewStore = tx.objectStore('journeysOverview');
-		const journeysHistoryStore = tx.objectStore('journeysHistory');
+		const journeysHistoryStore  = tx.objectStore('journeysHistory');
+
 		let proms = journeyEntries.map(j => {
 			journeyStore.put(j);
 		});

@@ -89,6 +94,7 @@ class IDBStorage {
 
 		proms.push(journeysOverviewStore.put(overviewEntry));
 		proms.push(tx.done);
+
 		await Promise.all(proms);
 	}
 

@@ -154,4 +160,4 @@ export const initDataStorage = async () => {
 
 export const clearDataStorage = () => {
 	deleteDB(dbName);
-}
+};