diff --git a/web/app/routes/api-internal.$teamSlug.$projectSlug.pageview-next.tsx b/web/app/routes/api-internal.$teamSlug.$projectSlug.pageview-next.tsx index 2e2af63..3eaa5e2 100644 --- a/web/app/routes/api-internal.$teamSlug.$projectSlug.pageview-next.tsx +++ b/web/app/routes/api-internal.$teamSlug.$projectSlug.pageview-next.tsx @@ -19,43 +19,50 @@ export type PageviewRequestData = { const parsePageviewRequestData = async (request: Request): Promise => { const data = (await request.json()) as PageviewRequestData; if (!data.data?.pathname) { - throw JSON.stringify({ pathname: `Pathname isn't defined` }); + throw new Error(JSON.stringify({ pathname: `Pathname isn't defined` })); } if (!data.date) { - throw JSON.stringify({ pathname: `Date isn't defined` }); + throw new Error(JSON.stringify({ pathname: `Date isn't defined` })); } if (!data.geo) { - throw JSON.stringify({ pathname: `geo isn't defined` }); + throw new Error(JSON.stringify({ pathname: `geo isn't defined` })); } if (!data.userAgentData) { - throw JSON.stringify({ pathname: `userAgentData isn't defined` }); + throw new Error(JSON.stringify({ pathname: `userAgentData isn't defined` })); } if (!data.user_hash) { - throw JSON.stringify({ pathname: `user_hash isn't defined` }); + throw new Error(JSON.stringify({ pathname: `user_hash isn't defined` })); } return data; }; const getLocation = async (geo: PageviewRequestData['geo']): Promise => { - const flag_country_city: Prisma.LocationFlagCountryCityCompoundUniqueInput = { flag: geo.flag, country: geo.country, city: geo.city }; + const country_city: Prisma.LocationCountryCityCompoundUniqueInput = { country: geo.country, city: geo.city }; const location: Prisma.LocationCreateWithoutPageViewsInput = { - ...flag_country_city, + ...country_city, + flag: geo.flag, latitude: Number(geo.latitude), longitude: Number(geo.longitude), }; return await prismaClient.location.upsert({ create: location, update: {}, - where: { flag_country_city }, + where: { country_city }, }); }; const trackPageviewNext = async (request: Request, project: Project) => { + console.info('[API-Internal - TrackPageviewNext] 0'); + const { data, date, geo, userAgentData, user_hash } = await parsePageviewRequestData(request); + console.info('[API-Internal - TrackPageviewNext] 1', { data, date, geo, userAgentData, user_hash }); + const location = await getLocation(geo); + console.info('[API-Internal - TrackPageviewNext] 2', { location }); + await prismaClient.pageViewNext.create({ data: { date, @@ -79,10 +86,9 @@ export const action = async ({ request, params }: ActionFunctionArgs) => { const { project } = await getProjectAndCheckPermissions(request, params.teamSlug, params.projectSlug); await trackPageviewNext(request, project); - - return json({ ok: true }, { status: 202 }); } catch (e) { console.error('[API-Internal - PageviewNext]', e); return json({ ok: false }, { status: 400 }); } + return json({ ok: true }, { status: 202 }); }; diff --git a/web/app/routes/api.$teamSlug.$projectSlug.pageview.tsx b/web/app/routes/api.$teamSlug.$projectSlug.pageview.tsx index 4517cb4..84d076c 100644 --- a/web/app/routes/api.$teamSlug.$projectSlug.pageview.tsx +++ b/web/app/routes/api.$teamSlug.$projectSlug.pageview.tsx @@ -44,8 +44,6 @@ const getPageViewNextRequest = async (request: Request): Promise