From 2b64460c0d9a229a2ee25eabe8c14b685e78ba95 Mon Sep 17 00:00:00 2001 From: Arun Alex Date: Tue, 30 Jul 2024 16:55:11 -0700 Subject: [PATCH 1/2] Inserted to user_clicks only when user clicks on other user's listing. --- apps/backend/listing/src/getListingById.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/backend/listing/src/getListingById.ts b/apps/backend/listing/src/getListingById.ts index 430dc623..836a3dfb 100755 --- a/apps/backend/listing/src/getListingById.ts +++ b/apps/backend/listing/src/getListingById.ts @@ -41,7 +41,8 @@ const getListingById = async ( l.created_at AS "dateCreated", l.modified_at AS "dateModified", l.image_urls, - l.charity_id AS "charityId" + l.charity_id AS "charityId", + l.seller_id FROM listings l JOIN @@ -56,12 +57,15 @@ const getListingById = async ( return res.status(200).json({ listing: {} }); } - const insertClickQuery = ` - INSERT INTO user_clicks (user_id, listing_id, listing_title) - VALUES ($1, $2, $3) - `; + console.log("UserID: " + userID + "Seller ID: " + listing.seller_id); + if(userID !== listing.seller_id) { + const insertClickQuery = ` + INSERT INTO user_clicks (user_id, listing_id, listing_title) + VALUES ($1, $2, $3) + `; - await db.oneOrNone(insertClickQuery, [userID, id, listing.title]); + await db.oneOrNone(insertClickQuery, [userID, id, listing.title]); + } const reviewsQuery = ` SELECT From 3dab25816b1d1f03a4de5fc3d585fff004953264 Mon Sep 17 00:00:00 2001 From: Arun Alex Date: Tue, 30 Jul 2024 17:01:29 -0700 Subject: [PATCH 2/2] Format. --- apps/backend/listing/src/getListingById.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/backend/listing/src/getListingById.ts b/apps/backend/listing/src/getListingById.ts index 836a3dfb..a33f6773 100755 --- a/apps/backend/listing/src/getListingById.ts +++ b/apps/backend/listing/src/getListingById.ts @@ -57,8 +57,7 @@ const getListingById = async ( return res.status(200).json({ listing: {} }); } - console.log("UserID: " + userID + "Seller ID: " + listing.seller_id); - if(userID !== listing.seller_id) { + if (userID !== listing.seller_id) { const insertClickQuery = ` INSERT INTO user_clicks (user_id, listing_id, listing_title) VALUES ($1, $2, $3)