From a91386434d7da52d1fc0f76c69cf15ecdc126521 Mon Sep 17 00:00:00 2001 From: Brian Cao Date: Mon, 26 Dec 2022 17:36:48 -0800 Subject: [PATCH] Remove snake_case. --- components/forms/EventDataForm.js | 4 ++-- components/forms/UserPasswordForm.js | 14 +++++------- components/metrics/EventsChart.js | 6 ++--- components/metrics/MetricsBar.js | 4 ++-- components/metrics/MetricsTable.js | 4 ++-- components/metrics/WebsiteChart.js | 4 ++-- components/pages/RealtimeDashboard.js | 2 +- lib/clickhouse.js | 12 +++++----- lib/prisma.ts | 8 +++---- pages/api/collect.ts | 2 +- pages/api/realtime/update.ts | 6 ++--- pages/api/teams/[id]/users.ts | 10 ++++----- pages/api/users/[id]/password.ts | 10 ++++----- pages/api/websites/[id]/eventdata.ts | 12 +++++----- pages/api/websites/[id]/events.ts | 14 ++++++------ pages/api/websites/[id]/metrics.ts | 12 +++++----- pages/api/websites/[id]/pageviews.ts | 12 +++++----- pages/api/websites/[id]/stats.ts | 26 +++++++--------------- queries/analytics/event/getEvents.js | 8 +++---- queries/analytics/pageview/getPageviews.js | 8 +++---- queries/analytics/session/getSessions.js | 8 +++---- 21 files changed, 86 insertions(+), 100 deletions(-) diff --git a/components/forms/EventDataForm.js b/components/forms/EventDataForm.js index 926e4a16..e72e90f8 100644 --- a/components/forms/EventDataForm.js +++ b/components/forms/EventDataForm.js @@ -109,8 +109,8 @@ export default function EventDataForm({ websiteId, onClose, className }) { const handleSubmit = async () => { const params = { website_id: websiteId, - start_at: +startDate, - end_at: +endDate, + startAt: +startDate, + endAt: +endDate, timezone, columns, filters, diff --git a/components/forms/UserPasswordForm.js b/components/forms/UserPasswordForm.js index 76748405..f386da0a 100644 --- a/components/forms/UserPasswordForm.js +++ b/components/forms/UserPasswordForm.js @@ -21,7 +21,7 @@ export default function UserPasswordForm({ onSave, userId }) { const payload = isCurrentUser ? data : { - password: data.new_password, + password: data.newPassword, }; mutate(payload, { @@ -33,7 +33,7 @@ export default function UserPasswordForm({ onSave, userId }) { }; const samePassword = value => { - if (value !== ref?.current?.getValues('new_password')) { + if (value !== ref?.current?.getValues('newPassword')) { return "Passwords don't match"; } return true; @@ -42,16 +42,12 @@ export default function UserPasswordForm({ onSave, userId }) { return (
{isCurrentUser && ( - + )} `'${a}'`).join(',') || ''; } -function getBetweenDates(field, start_at, end_at) { - return `${field} between ${getDateFormat(start_at)} and ${getDateFormat(end_at)}`; +function getBetweenDates(field, startAt, endAt) { + return `${field} between ${getDateFormat(startAt)} and ${getDateFormat(endAt)}`; } function getJsonField(column, property) { @@ -120,7 +120,7 @@ function getFilterQuery(filters = {}, params = []) { case 'browser': case 'device': case 'country': - case 'event_name': + case 'eventName': arr.push(`and ${key}=$${params.length + 1}`); params.push(decodeURIComponent(filter)); break; @@ -147,18 +147,18 @@ function getFilterQuery(filters = {}, params = []) { } function parseFilters(filters = {}, params = []) { - const { domain, url, event_url, referrer, os, browser, device, country, event_name, query } = + const { domain, url, event_url, referrer, os, browser, device, country, eventName, query } = filters; const pageviewFilters = { domain, url, referrer, query }; const sessionFilters = { os, browser, device, country }; - const eventFilters = { url: event_url, event_name }; + const eventFilters = { url: event_url, eventName }; return { pageviewFilters, sessionFilters, eventFilters, - event: { event_name }, + event: { eventName }, filterQuery: getFilterQuery(filters, params), }; } diff --git a/lib/prisma.ts b/lib/prisma.ts index 08cfb0e0..e7c16a5c 100644 --- a/lib/prisma.ts +++ b/lib/prisma.ts @@ -159,7 +159,7 @@ function getFilterQuery(filters = {}, params = []): string { case 'browser': case 'device': case 'country': - case 'event_name': + case 'eventName': arr.push(`and ${key}=$${params.length + 1}`); params.push(decodeURIComponent(filter)); break; @@ -187,18 +187,18 @@ function parseFilters( params = [], sessionKey = 'session_id', ) { - const { domain, url, event_url, referrer, os, browser, device, country, event_name, query } = + const { domain, url, event_url, referrer, os, browser, device, country, eventName, query } = filters; const pageviewFilters = { domain, url, referrer, query }; const sessionFilters = { os, browser, device, country }; - const eventFilters = { url: event_url, event_name }; + const eventFilters = { url: event_url, eventName }; return { pageviewFilters, sessionFilters, eventFilters, - event: { event_name }, + event: { eventName }, joinSession: os || browser || device || country ? `inner join session on ${sessionKey} = session.${sessionKey}` diff --git a/pages/api/collect.ts b/pages/api/collect.ts index 9246c9c6..b288d991 100644 --- a/pages/api/collect.ts +++ b/pages/api/collect.ts @@ -31,7 +31,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => { const { type, payload } = getJsonBody(req); - const { referrer, event_name: eventName, event_data: eventData } = payload; + const { referrer, eventName, event_data: eventData } = payload; let { url } = payload; // Validate eventData is JSON diff --git a/pages/api/realtime/update.ts b/pages/api/realtime/update.ts index 9b99a282..9c9efc25 100644 --- a/pages/api/realtime/update.ts +++ b/pages/api/realtime/update.ts @@ -8,7 +8,7 @@ import { NextApiResponse } from 'next'; import { RealtimeUpdate } from 'lib/types'; export interface InitUpdateRequestQuery { - start_at: string; + startAt: string; } export default async ( @@ -18,7 +18,7 @@ export default async ( await useAuth(req, res); if (req.method === 'GET') { - const { start_at } = req.query; + const { startAt } = req.query; const token = req.headers[SHARE_TOKEN_HEADER]; @@ -28,7 +28,7 @@ export default async ( const { websites } = parseToken(token, secret()); - const data = await getRealtimeData(websites, new Date(+start_at)); + const data = await getRealtimeData(websites, new Date(+startAt)); return ok(res, data); } diff --git a/pages/api/teams/[id]/users.ts b/pages/api/teams/[id]/users.ts index f0e34165..e90dc648 100644 --- a/pages/api/teams/[id]/users.ts +++ b/pages/api/teams/[id]/users.ts @@ -11,8 +11,8 @@ export interface TeamUserRequestQuery { export interface TeamUserRequestBody { email: string; - role_id: string; - team_user_id?: string; + roleId: string; + teamUserId?: string; } export default async ( @@ -41,7 +41,7 @@ export default async ( return unauthorized(res, 'You must be the owner of this team.'); } - const { email, role_id: roleId } = req.body; + const { email, roleId: roleId } = req.body; // Check for User const user = await getUser({ username: email }); @@ -59,9 +59,9 @@ export default async ( if (await canUpdateTeam(userId, teamId)) { return unauthorized(res, 'You must be the owner of this team.'); } - const { team_user_id } = req.body; + const { teamUserId } = req.body; - await deleteTeamUser(team_user_id); + await deleteTeamUser(teamUserId); return ok(res); } diff --git a/pages/api/users/[id]/password.ts b/pages/api/users/[id]/password.ts index 5bae1729..8fabb355 100644 --- a/pages/api/users/[id]/password.ts +++ b/pages/api/users/[id]/password.ts @@ -17,8 +17,8 @@ export interface UserPasswordRequestQuery { } export interface UserPasswordRequestBody { - current_password: string; - new_password: string; + currentPassword: string; + newPassword: string; } export default async ( @@ -27,7 +27,7 @@ export default async ( ) => { await useAuth(req, res); - const { current_password, new_password } = req.body; + const { currentPassword, newPassword } = req.body; const { id } = req.query; const { user: { id: userId, isAdmin }, @@ -40,11 +40,11 @@ export default async ( const user = await getUser({ id }, { includePassword: true }); - if (!checkPassword(current_password, user.password)) { + if (!checkPassword(currentPassword, user.password)) { return badRequest(res, 'Current password is incorrect'); } - const password = hashPassword(new_password); + const password = hashPassword(newPassword); const updated = await updateUser({ password }, { id }); diff --git a/pages/api/websites/[id]/eventdata.ts b/pages/api/websites/[id]/eventdata.ts index 9293cbad..28997116 100644 --- a/pages/api/websites/[id]/eventdata.ts +++ b/pages/api/websites/[id]/eventdata.ts @@ -10,9 +10,9 @@ export interface WebsiteEventDataRequestQuery { } export interface WebsiteEventDataRequestBody { - start_at: string; - end_at: string; - event_name: string; + startAt: string; + endAt: string; + eventName: string; columns: { [key: string]: 'count' | 'max' | 'min' | 'avg' | 'sum' }; filters?: { [key: string]: any }; } @@ -34,10 +34,10 @@ export default async ( return unauthorized(res); } - const { start_at, end_at, event_name: eventName, columns, filters } = req.body; + const { startAt, endAt, event_name: eventName, columns, filters } = req.body; - const startDate = new Date(+start_at); - const endDate = new Date(+end_at); + const startDate = new Date(+startAt); + const endDate = new Date(+endAt); const events = await getEventData(websiteId, { startDate, diff --git a/pages/api/websites/[id]/events.ts b/pages/api/websites/[id]/events.ts index 726669a3..088f2ff4 100644 --- a/pages/api/websites/[id]/events.ts +++ b/pages/api/websites/[id]/events.ts @@ -10,12 +10,12 @@ const unitTypes = ['year', 'month', 'hour', 'day']; export interface WebsiteEventsRequestQuery { id: string; - start_at: string; - end_at: string; + startAt: string; + endAt: string; unit: string; tz: string; url: string; - event_name: string; + eventName: string; } export default async ( @@ -28,7 +28,7 @@ export default async ( const { user: { id: userId }, } = req.auth; - const { id: websiteId, start_at, end_at, unit, tz, url, event_name } = req.query; + const { id: websiteId, startAt, endAt, unit, tz, url, eventName } = req.query; if (req.method === 'GET') { if (canViewWebsite(userId, websiteId)) { @@ -38,8 +38,8 @@ export default async ( if (!moment.tz.zone(tz) || !unitTypes.includes(unit)) { return badRequest(res); } - const startDate = new Date(+start_at); - const endDate = new Date(+end_at); + const startDate = new Date(+startAt); + const endDate = new Date(+endAt); const events = await getEventMetrics(websiteId, { startDate, @@ -48,7 +48,7 @@ export default async ( unit, filters: { url, - eventName: event_name, + eventName, }, }); diff --git a/pages/api/websites/[id]/metrics.ts b/pages/api/websites/[id]/metrics.ts index 260814da..04a27129 100644 --- a/pages/api/websites/[id]/metrics.ts +++ b/pages/api/websites/[id]/metrics.ts @@ -38,8 +38,8 @@ function getColumn(type) { export interface WebsiteMetricsRequestQuery { id: string; type: string; - start_at: number; - end_at: number; + startAt: number; + endAt: number; url: string; referrer: string; os: string; @@ -61,8 +61,8 @@ export default async ( const { id: websiteId, type, - start_at, - end_at, + startAt, + endAt, url, referrer, os, @@ -76,8 +76,8 @@ export default async ( return unauthorized(res); } - const startDate = new Date(+start_at); - const endDate = new Date(+end_at); + const startDate = new Date(+startAt); + const endDate = new Date(+endAt); if (sessionColumns.includes(type)) { let data = await getSessionMetrics(websiteId, { diff --git a/pages/api/websites/[id]/pageviews.ts b/pages/api/websites/[id]/pageviews.ts index ea6c5df4..098a3192 100644 --- a/pages/api/websites/[id]/pageviews.ts +++ b/pages/api/websites/[id]/pageviews.ts @@ -11,8 +11,8 @@ const unitTypes = ['year', 'month', 'hour', 'day']; export interface WebsitePageviewRequestQuery { id: string; websiteId: string; - start_at: number; - end_at: number; + startAt: number; + endAt: number; unit: string; tz: string; url?: string; @@ -35,8 +35,8 @@ export default async ( } = req.auth; const { id: websiteId, - start_at, - end_at, + startAt, + endAt, unit, tz, url, @@ -52,8 +52,8 @@ export default async ( return unauthorized(res); } - const startDate = new Date(+start_at); - const endDate = new Date(+end_at); + const startDate = new Date(+startAt); + const endDate = new Date(+endAt); if (!moment.tz.zone(tz) || !unitTypes.includes(unit)) { return badRequest(res); diff --git a/pages/api/websites/[id]/stats.ts b/pages/api/websites/[id]/stats.ts index 85c4f254..f0ce4b6b 100644 --- a/pages/api/websites/[id]/stats.ts +++ b/pages/api/websites/[id]/stats.ts @@ -9,8 +9,8 @@ import { getWebsiteStats } from 'queries'; export interface WebsiteStatsRequestQuery { id: string; type: string; - start_at: number; - end_at: number; + startAt: number; + endAt: number; url: string; referrer: string; os: string; @@ -29,29 +29,19 @@ export default async ( const { user: { id: userId }, } = req.auth; - const { - id: websiteId, - start_at, - end_at, - url, - referrer, - os, - browser, - device, - country, - } = req.query; + const { id: websiteId, startAt, endAt, url, referrer, os, browser, device, country } = req.query; if (req.method === 'GET') { if (!(await canViewWebsite(userId, websiteId))) { return unauthorized(res); } - const startDate = new Date(+start_at); - const endDate = new Date(+end_at); + const startDate = new Date(+startAt); + const endDate = new Date(+endAt); - const distance = end_at - start_at; - const prevStartDate = new Date(+start_at - distance); - const prevEndDate = new Date(+end_at - distance); + const distance = endAt - startAt; + const prevStartDate = new Date(+startAt - distance); + const prevEndDate = new Date(+endAt - distance); const metrics = await getWebsiteStats(websiteId, { startDate, diff --git a/queries/analytics/event/getEvents.js b/queries/analytics/event/getEvents.js index 81a187ce..742bd051 100644 --- a/queries/analytics/event/getEvents.js +++ b/queries/analytics/event/getEvents.js @@ -9,20 +9,20 @@ export function getEvents(...args) { }); } -function relationalQuery(websites, start_at) { +function relationalQuery(websites, startAt) { return prisma.client.event.findMany({ where: { websiteId: { in: websites, }, createdAt: { - gte: start_at, + gte: startAt, }, }, }); } -function clickhouseQuery(websites, start_at) { +function clickhouseQuery(websites, startAt) { const { rawQuery, getDateFormat, getCommaSeparatedStringFormat } = clickhouse; return rawQuery( @@ -40,6 +40,6 @@ function clickhouseQuery(websites, start_at) { ? `website_id in (${getCommaSeparatedStringFormat(websites)})` : '0 = 0' } - and created_at >= ${getDateFormat(start_at)}`, + and created_at >= ${getDateFormat(startAt)}`, ); } diff --git a/queries/analytics/pageview/getPageviews.js b/queries/analytics/pageview/getPageviews.js index 2bf41b0b..03f8a485 100644 --- a/queries/analytics/pageview/getPageviews.js +++ b/queries/analytics/pageview/getPageviews.js @@ -9,20 +9,20 @@ export async function getPageviews(...args) { }); } -async function relationalQuery(websites, start_at) { +async function relationalQuery(websites, startAt) { return prisma.client.pageview.findMany({ where: { websiteId: { in: websites, }, createdAt: { - gte: start_at, + gte: startAt, }, }, }); } -async function clickhouseQuery(websites, start_at) { +async function clickhouseQuery(websites, startAt) { const { rawQuery, getCommaSeparatedStringFormat } = clickhouse; return rawQuery( @@ -38,6 +38,6 @@ async function clickhouseQuery(websites, start_at) { ? `website_id in (${getCommaSeparatedStringFormat(websites)})` : '0 = 0' } - and created_at >= ${clickhouse.getDateFormat(start_at)}`, + and created_at >= ${clickhouse.getDateFormat(startAt)}`, ); } diff --git a/queries/analytics/session/getSessions.js b/queries/analytics/session/getSessions.js index c5fed485..ad38a5f7 100644 --- a/queries/analytics/session/getSessions.js +++ b/queries/analytics/session/getSessions.js @@ -9,7 +9,7 @@ export async function getSessions(...args) { }); } -async function relationalQuery(websites, start_at) { +async function relationalQuery(websites, startAt) { return prisma.client.session.findMany({ where: { ...(websites && websites.length > 0 @@ -20,13 +20,13 @@ async function relationalQuery(websites, start_at) { } : {}), createdAt: { - gte: start_at, + gte: startAt, }, }, }); } -async function clickhouseQuery(websites, start_at) { +async function clickhouseQuery(websites, startAt) { const { rawQuery, getDateFormat, getCommaSeparatedStringFormat } = clickhouse; return rawQuery( @@ -47,6 +47,6 @@ async function clickhouseQuery(websites, start_at) { ? `website_id in (${getCommaSeparatedStringFormat(websites)})` : '0 = 0' } - and created_at >= ${getDateFormat(start_at)}`, + and created_at >= ${getDateFormat(startAt)}`, ); }