From 3072f02f1bc2a5fad3347a0389706ea087029aeb Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Fri, 19 Dec 2025 13:32:20 -0800 Subject: [PATCH 1/2] =?UTF-8?q?Add=20table=20alias=20to=20filterQuery.=20C?= =?UTF-8?q?losed=20=C2=A0#3869?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/prisma.ts | 14 ++++++++++---- src/queries/sql/reports/getRevenue.ts | 7 ++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index 64cb870f..bfd007d1 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -74,15 +74,21 @@ function getSearchSQL(column: string, param: string = 'search'): string { function mapFilter(column: string, operator: string, name: string, type: string = '') { const value = `{{${name}${type ? `::${type}` : ''}}}`; + if (name.startsWith('cohort_')) { + name = name.slice('cohort_'.length); + } + + const table = SESSION_COLUMNS.includes(name) ? 'session' : 'website_event'; + switch (operator) { case OPERATORS.equals: - return `${column} = ${value}`; + return `${table}.${column} = ${value}`; case OPERATORS.notEquals: - return `${column} != ${value}`; + return `${table}.${column} != ${value}`; case OPERATORS.contains: - return `${column} ilike ${value}`; + return `${table}.${column} ilike ${value}`; case OPERATORS.doesNotContain: - return `${column} not ilike ${value}`; + return `${table}.${column} not ilike ${value}`; default: return ''; } diff --git a/src/queries/sql/reports/getRevenue.ts b/src/queries/sql/reports/getRevenue.ts index 19b75d42..2a4604fe 100644 --- a/src/queries/sql/reports/getRevenue.ts +++ b/src/queries/sql/reports/getRevenue.ts @@ -41,14 +41,15 @@ async function relationalQuery( currency, }); - const joinQuery = filterQuery - ? `join website_event + const joinQuery = + filterQuery || cohortQuery + ? `join website_event on website_event.website_id = revenue.website_id and website_event.session_id = revenue.session_id and website_event.event_id = revenue.event_id and website_event.website_id = {{websiteId::uuid}} and website_event.created_at between {{startDate}} and {{endDate}}` - : ''; + : ''; const chart = await rawQuery( ` From 912d2d544dac632cf08064a08deb46ac9a07bcd4 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Fri, 19 Dec 2025 14:21:42 -0800 Subject: [PATCH 2/2] Fix deleted website visibility bug Closes #3865 --- src/app/(main)/links/[linkId]/page.tsx | 6 ++++++ src/app/(main)/pixels/[pixelId]/page.tsx | 6 ++++++ src/app/(main)/websites/[websiteId]/layout.tsx | 6 ++++++ src/lib/request.ts | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/(main)/links/[linkId]/page.tsx b/src/app/(main)/links/[linkId]/page.tsx index 4317ada2..3a5f5d7e 100644 --- a/src/app/(main)/links/[linkId]/page.tsx +++ b/src/app/(main)/links/[linkId]/page.tsx @@ -1,8 +1,14 @@ import type { Metadata } from 'next'; +import { getLink } from '@/queries/prisma'; import { LinkPage } from './LinkPage'; export default async function ({ params }: { params: Promise<{ linkId: string }> }) { const { linkId } = await params; + const link = await getLink(linkId); + + if (!link || link?.deletedAt) { + return null; + } return ; } diff --git a/src/app/(main)/pixels/[pixelId]/page.tsx b/src/app/(main)/pixels/[pixelId]/page.tsx index d1db92f3..e174c195 100644 --- a/src/app/(main)/pixels/[pixelId]/page.tsx +++ b/src/app/(main)/pixels/[pixelId]/page.tsx @@ -1,8 +1,14 @@ import type { Metadata } from 'next'; +import { getPixel } from '@/queries/prisma'; import { PixelPage } from './PixelPage'; export default async function ({ params }: { params: { pixelId: string } }) { const { pixelId } = await params; + const pixel = await getPixel(pixelId); + + if (!pixel || pixel?.deletedAt) { + return null; + } return ; } diff --git a/src/app/(main)/websites/[websiteId]/layout.tsx b/src/app/(main)/websites/[websiteId]/layout.tsx index 67595e9d..b12ff950 100644 --- a/src/app/(main)/websites/[websiteId]/layout.tsx +++ b/src/app/(main)/websites/[websiteId]/layout.tsx @@ -1,5 +1,6 @@ import type { Metadata } from 'next'; import { WebsiteLayout } from '@/app/(main)/websites/[websiteId]/WebsiteLayout'; +import { getWebsite } from '@/queries/prisma'; export default async function ({ children, @@ -9,6 +10,11 @@ export default async function ({ params: Promise<{ websiteId: string }>; }) { const { websiteId } = await params; + const website = await getWebsite(websiteId); + + if (!website || website?.deletedAt) { + return null; + } return {children}; } diff --git a/src/lib/request.ts b/src/lib/request.ts index e6450bf3..d6543b18 100644 --- a/src/lib/request.ts +++ b/src/lib/request.ts @@ -85,7 +85,7 @@ export async function setWebsiteDate(websiteId: string, userId: string, data: Re const website = await fetchWebsite(websiteId); const cloudMode = !!process.env.CLOUD_MODE; - if (cloudMode && !website.teamId) { + if (cloudMode && website && !website.teamId) { const account = await fetchAccount(userId); if (!account?.hasSubscription) {