From ccb757ec3e878ff6e81b4e7e20a9acdc91cea13a Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Mon, 16 Dec 2024 20:58:56 +0100 Subject: [PATCH] fix: missed transaction --- backend/src/services/auth-token/auth-token-dal.ts | 7 +++++-- backend/src/services/auth-token/auth-token-service.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/services/auth-token/auth-token-dal.ts b/backend/src/services/auth-token/auth-token-dal.ts index ed45d505e..221b691cf 100644 --- a/backend/src/services/auth-token/auth-token-dal.ts +++ b/backend/src/services/auth-token/auth-token-dal.ts @@ -12,9 +12,12 @@ export type TTokenDALFactory = ReturnType; export const tokenDALFactory = (db: TDbClient) => { const authOrm = ormify(db, TableName.AuthTokens); - const findOneTokenSession = async (filter: Partial): Promise => { + const findOneTokenSession = async ( + filter: Partial, + tx?: Knex + ): Promise => { try { - const doc = await db.replicaNode()(TableName.AuthTokenSession).where(filter).first(); + const doc = await (tx || db.replicaNode())(TableName.AuthTokenSession).where(filter).first(); return doc; } catch (error) { throw new DatabaseError({ error, name: "FindOneTokenSession" }); diff --git a/backend/src/services/auth-token/auth-token-service.ts b/backend/src/services/auth-token/auth-token-service.ts index b9fc98106..c0bb7dc17 100644 --- a/backend/src/services/auth-token/auth-token-service.ts +++ b/backend/src/services/auth-token/auth-token-service.ts @@ -128,7 +128,7 @@ export const tokenServiceFactory = ({ tokenDAL, userDAL, orgMembershipDAL }: TAu { userId, ip, userAgent }: TIssueAuthTokenDTO, tx?: Knex ): Promise => { - let session = await tokenDAL.findOneTokenSession({ userId, ip, userAgent }); + let session = await tokenDAL.findOneTokenSession({ userId, ip, userAgent }, tx); if (!session) { session = await tokenDAL.insertTokenSession(userId, ip, userAgent, tx); }