Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert to user_clicks only when user clicks on other user's listing. #552

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions apps/backend/listing/src/getListingById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,12 +57,14 @@ 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)
`;
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
Expand Down