From 7f393276a849d7c4069a14849a2f883012e1c761 Mon Sep 17 00:00:00 2001 From: Adrian Wannenmacher Date: Mon, 9 Mar 2026 20:49:01 +0100 Subject: [PATCH] simplify session repo insertion method --- data/session_repo.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/data/session_repo.js b/data/session_repo.js index d216423..2a83b1b 100644 --- a/data/session_repo.js +++ b/data/session_repo.js @@ -99,7 +99,7 @@ export default class SessionRepo { * * @returns {Promise} A promise containing the ID of the add session. */ - static put(session, transaction) { + static async put(session, transaction) { if (!(session instanceof Session)) throw new TypeError("session to put in must be an actual Session"); @@ -107,20 +107,13 @@ export default class SessionRepo { let sessions = transaction.objectStore(WbDb.OS_SESSIONS); let struct = session.toStruct(); - let req = requestToPromise(sessions.put(struct)); + let id = await requestToPromise(sessions.put(struct)); - // promise with which the session object can be altered - let alt = req; - - // add id to original object if it is new if (session.id === null) - alt = alt.then((id) => session.id = id); + session.id = id; + SessionRepo.#setupChangeHandling(session, transaction.db); - // add change listener to object. - alt.then(() => SessionRepo.#setupChangeHandling(session, transaction.db)); - - // make sure alt is handled first - return req.then(res => res); + return id; } /** Get a specific session from the repository.