1
0

simplify session repo insertion method

This commit is contained in:
Adrian Wannenmacher 2026-03-09 20:49:01 +01:00
parent fbe785c1c4
commit 7f393276a8
Signed by: tfld
GPG Key ID: 19D986ECB1E492D5

View File

@ -99,7 +99,7 @@ export default class SessionRepo {
* *
* @returns {Promise<number>} A promise containing the ID of the add session. * @returns {Promise<number>} A promise containing the ID of the add session.
*/ */
static put(session, transaction) { static async put(session, transaction) {
if (!(session instanceof Session)) if (!(session instanceof Session))
throw new TypeError("session to put in must be an actual 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 sessions = transaction.objectStore(WbDb.OS_SESSIONS);
let struct = session.toStruct(); 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) if (session.id === null)
alt = alt.then((id) => session.id = id); session.id = id;
SessionRepo.#setupChangeHandling(session, transaction.db);
// add change listener to object. return id;
alt.then(() => SessionRepo.#setupChangeHandling(session, transaction.db));
// make sure alt is handled first
return req.then(res => res);
} }
/** Get a specific session from the repository. /** Get a specific session from the repository.