From 9dd9ab1325ff08fdd8329524d769400e93bec1a6 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Thu, 13 Apr 2023 22:40:48 -0700 Subject: [PATCH] concatenate subdivision saves --- queries/analytics/event/saveEvent.ts | 2 +- queries/analytics/session/createSession.ts | 32 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/queries/analytics/event/saveEvent.ts b/queries/analytics/event/saveEvent.ts index 332b349c..2dcb8849 100644 --- a/queries/analytics/event/saveEvent.ts +++ b/queries/analytics/event/saveEvent.ts @@ -137,7 +137,7 @@ async function clickhouseQuery(data: { session_id: sessionId, event_id: eventId, country: country ? country : null, - subdivision1: subdivision1 ? subdivision1 : null, + subdivision1: subdivision1 ? country.concat('-', subdivision1) : null, subdivision2: subdivision2 ? subdivision2 : null, city: city ? city : null, url_path: urlPath?.substring(0, URL_LENGTH), diff --git a/queries/analytics/session/createSession.ts b/queries/analytics/session/createSession.ts index d2657d60..7286cb97 100644 --- a/queries/analytics/session/createSession.ts +++ b/queries/analytics/session/createSession.ts @@ -18,7 +18,37 @@ export async function createSession(args: Prisma.SessionCreateInput) { } async function relationalQuery(data: Prisma.SessionCreateInput) { - return prisma.client.session.create({ data }); + const { + id, + websiteId, + hostname, + browser, + os, + device, + screen, + language, + country, + subdivision1, + subdivision2, + city, + } = data; + + return prisma.client.session.create({ + data: { + id, + websiteId, + hostname, + browser, + os, + device, + screen, + language, + country, + subdivision1: country.concat('-', subdivision1), + subdivision2, + city, + }, + }); } async function clickhouseQuery(data: {