From c5dbe2a3e4c4aed545193f23caa7414a2f17fb66 Mon Sep 17 00:00:00 2001 From: Alexejhero <32238504+Alexejhero@users.noreply.github.com> Date: Tue, 11 Jun 2024 01:28:58 +0200 Subject: [PATCH] fix log i think --- ebs/src/util/db.ts | 5 +++-- logger/src/util/db.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ebs/src/util/db.ts b/ebs/src/util/db.ts index 0bc1143..b33d828 100644 --- a/ebs/src/util/db.ts +++ b/ebs/src/util/db.ts @@ -39,7 +39,8 @@ export async function setupDb() { await db.query(` CREATE TABLE IF NOT EXISTS prepurchases ( token VARCHAR(255) PRIMARY KEY, - cart JSON NOT NULL + cart JSON NOT NULL, + userId VARCHAR(255) NOT NULL ) `); @@ -75,7 +76,7 @@ export async function addFulfilledTransaction(receipt: string, token: string, us export async function registerPrepurchase(cart: IdentifiableCart): Promise { try { const token = uuid(); - await db.query("INSERT INTO prepurchases (token, cart) VALUES (?, ?)", [token, JSON.stringify(cart)]); + await db.query("INSERT INTO prepurchases (token, cart, userId) VALUES (?, ?, ?)", [token, JSON.stringify(cart), cart.userId]); return token; } catch (e: any) { console.error("Database query failed (registerPrepurchase)"); diff --git a/logger/src/util/db.ts b/logger/src/util/db.ts index 2c130c7..6fe45c1 100644 --- a/logger/src/util/db.ts +++ b/logger/src/util/db.ts @@ -21,8 +21,13 @@ export async function canLog(token: string | null): Promise { export async function getUserIdFromTransactionToken(token: string): Promise { try { - const [rows] = (await db.query("SELECT userId FROM transactions WHERE token = ?", [token])) as [RowDataPacket[], any]; - return rows[0].userId; + try { + const [rows] = (await db.query("SELECT userId FROM prepurchases WHERE token = ?", [token])) as [RowDataPacket[], any]; + return rows[0].userId; + } catch (e: any) { + const [rows] = (await db.query("SELECT userId FROM transactions WHERE token = ?", [token])) as [RowDataPacket[], any]; + return rows[0].userId; + } } catch (e: any) { console.error("Database query failed (getUserIdFromTransactionToken)"); console.error(e);