Skip to content

Commit

Permalink
fix log i think
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexejhero committed Jun 10, 2024
1 parent ddec0d8 commit c5dbe2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions ebs/src/util/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
`);

Expand Down Expand Up @@ -75,7 +76,7 @@ export async function addFulfilledTransaction(receipt: string, token: string, us
export async function registerPrepurchase(cart: IdentifiableCart): Promise<string> {
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)");
Expand Down
9 changes: 7 additions & 2 deletions logger/src/util/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ export async function canLog(token: string | null): Promise<boolean> {

export async function getUserIdFromTransactionToken(token: string): Promise<string | null> {
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);
Expand Down

0 comments on commit c5dbe2a

Please sign in to comment.