Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Fixed queries again.

Mike Cao1ba28ece8b21
diff --git a/src/app/api/reports/goals/route.ts b/src/app/api/reports/goals/route.ts
index b419c5697..5a2f6bd0c 100644
--- a/src/app/api/reports/goals/route.ts
+++ b/src/app/api/reports/goals/route.ts
@@ -2,7 +2,7 @@ import { z } from 'zod';
import { canViewWebsite } from '@/lib/auth';
import { unauthorized, json } from '@/lib/response';
import { parseRequest } from '@/lib/request';
-import { getGoals } from '@/queries/analytics/reports/getGoals';
+import { getGoals } from '@/queries/sql/reports/getGoals';
import { reportParms } from '@/lib/schema';
export async function POST(request: Request) {
diff --git a/src/app/api/reports/revenue/route.ts b/src/app/api/reports/revenue/route.ts
index db7d036bb..f8f4041fd 100644
--- a/src/app/api/reports/revenue/route.ts
+++ b/src/app/api/reports/revenue/route.ts
@@ -3,8 +3,8 @@ import { canViewWebsite } from '@/lib/auth';
import { unauthorized, json } from '@/lib/response';
import { parseRequest } from '@/lib/request';
import { reportParms, timezoneParam } from '@/lib/schema';
-import { getRevenue } from '@/queries/analytics/reports/getRevenue';
-import { getRevenueValues } from '@/queries/analytics/reports/getRevenueValues';
+import { getRevenue } from '@/queries/sql/reports/getRevenue';
+import { getRevenueValues } from '@/queries/sql/reports/getRevenueValues';
export async function GET(request: Request) {
const { auth, query, error } = await parseRequest(request);
diff --git a/src/app/api/users/[userId]/usage/route.ts b/src/app/api/users/[userId]/usage/route.ts
index 168ae42e0..e6ff217d6 100644
--- a/src/app/api/users/[userId]/usage/route.ts
+++ b/src/app/api/users/[userId]/usage/route.ts
@@ -1,8 +1,8 @@
import { z } from 'zod';
import { json, unauthorized } from '@/lib/response';
import { getAllUserWebsitesIncludingTeamOwner } from '@/queries/prisma/website';
-import { getEventUsage } from '@/queries/analytics/events/getEventUsage';
-import { getEventDataUsage } from '@/queries/analytics/events/getEventDataUsage';
+import { getEventUsage } from '@/queries/sql/events/getEventUsage';
+import { getEventDataUsage } from '@/queries/sql/events/getEventDataUsage';
import { parseRequest } from '@/lib/request';
export async function GET(request: Request, { params }: { params: Promise<{ userId: string }> }) {
diff --git a/src/app/api/websites/[websiteId]/event-data/events/route.ts b/src/app/api/websites/[websiteId]/event-data/events/route.ts
index 3e32aa838..aec7b4713 100644
--- a/src/app/api/websites/[websiteId]/event-data/events/route.ts
+++ b/src/app/api/websites/[websiteId]/event-data/events/route.ts
@@ -2,7 +2,7 @@ import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
-import { getEventDataEvents } from '@/queries/analytics/events/getEventDataEvents';
+import { getEventDataEvents } from '@/queries/sql/events/getEventDataEvents';
export async function GET(
request: Request,
diff --git a/src/app/api/websites/[websiteId]/metrics/route.ts b/src/app/api/websites/[websiteId]/metrics/route.ts
index 17c8676f0..50bfc3871 100644
--- a/src/app/api/websites/[websiteId]/metrics/route.ts
+++ b/src/app/api/websites/[websiteId]/metrics/route.ts
@@ -3,7 +3,7 @@ import { canViewWebsite } from '@/lib/auth';
import { SESSION_COLUMNS, EVENT_COLUMNS, FILTER_COLUMNS, OPERATORS } from '@/lib/constants';
import { getRequestFilters, getRequestDateRange, parseRequest } from '@/lib/request';
import { json, unauthorized, badRequest } from '@/lib/response';
-import { getPageviewMetrics, getSessionMetrics } from '@/queries';
+import { getPageviewMetrics, getSessionMetrics, getChannelMetrics } from '@/queries';
import { filterParams } from '@/lib/schema';
export async function GET(
@@ -78,5 +78,11 @@ export async function GET(
return json(data);
}
+ if (type === 'channel') {
+ const data = await getChannelMetrics(websiteId, filters);
+
+ return json(data);
+ }
+
return badRequest();
}
diff --git a/src/app/api/websites/[websiteId]/session-data/values/route.ts b/src/app/api/websites/[websiteId]/session-data/values/route.ts
index 1c12f00d9..93e91775e 100644
--- a/src/app/api/websites/[websiteId]/session-data/values/route.ts
+++ b/src/app/api/websites/[websiteId]/session-data/values/route.ts
@@ -2,7 +2,7 @@ import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
-import { getEventDataEvents } from '@/queries/analytics/events/getEventDataEvents';
+import { getEventDataEvents } from '@/queries/sql/events/getEventDataEvents';
export async function GET(
request: Request,
diff --git a/src/components/hooks/useApi.ts b/src/components/hooks/useApi.ts
index 7684f4e4e..be386a296 100644
--- a/src/components/hooks/useApi.ts
+++ b/src/components/hooks/useApi.ts
@@ -27,8 +27,8 @@ export function useApi() {
};
const basePath = process.env.basePath;
- const getUrl = (url: string, basePath = '') => {
- return url.startsWith('http') ? url : `${basePath}/api${url}`;
+ const getUrl = (url: string) => {
+ return url.startsWith('http') ? url : `${basePath || ''}/api${url}`;
};
const getHeaders = (headers: any = {}) => {
@@ -38,7 +38,7 @@ export function useApi() {
return {
get: useCallback(
async (url: string, params: object = {}, headers: object = {}) => {
- return httpGet(getUrl(url, basePath), params, getHeaders(headers))
+ return httpGet(getUrl(url), params, getHeaders(headers))
.then(handleResponse)
.catch(handleError);
},
@@ -47,7 +47,7 @@ export function useApi() {
post: useCallback(
async (url: string, params: object = {}, headers: object = {}) => {
- return httpPost(getUrl(url, basePath), params, getHeaders(headers))
+ return httpPost(getUrl(url), params, getHeaders(headers))
.then(handleResponse)
.catch(handleError);
},
@@ -56,7 +56,7 @@ export function useApi() {
put: useCallback(
async (url: string, params: object = {}, headers: object = {}) => {
- return httpPut(getUrl(url, basePath), params, getHeaders(headers))
+ return httpPut(getUrl(url), params, getHeaders(headers))
.then(handleResponse)
.catch(handleError);
},
@@ -65,7 +65,7 @@ export function useApi() {
del: useCallback(
async (url: string, params: object = {}, headers: object = {}) => {
- return httpDelete(getUrl(url, basePath), params, getHeaders(headers))
+ return httpDelete(getUrl(url), params, getHeaders(headers))
.then(handleResponse)
.catch(handleError);
},
diff --git a/src/lib/fetch.ts b/src/lib/fetch.ts
index e5068b29a..754da56f1 100644
--- a/src/lib/fetch.ts
+++ b/src/lib/fetch.ts
@@ -1,7 +1,7 @@
import { buildUrl } from '@/lib/url';
export async function request(method: string, url: string, body?: string, headers: object = {}) {
- const res = await fetch(url, {
+ return fetch(url, {
method,
cache: 'no-cache',
headers: {
@@ -10,22 +10,21 @@ export async function request(method: string, url: string, body?: string, header
...headers,
},
body,
- });
- return res.json();
+ }).then(res => res.json());
}
-export function httpGet(url: string, params: object = {}, headers: object = {}) {
+export async function httpGet(url: string, params: object = {}, headers: object = {}) {
return request('GET', buildUrl(url, params), undefined, headers);
}
-export function httpDelete(url: string, params: object = {}, headers: object = {}) {
+export async function httpDelete(url: string, params: object = {}, headers: object = {}) {
return request('DELETE', buildUrl(url, params), undefined, headers);
}
-export function httpPost(url: string, params: object = {}, headers: object = {}) {
+export async function httpPost(url: string, params: object = {}, headers: object = {}) {
return request('POST', url, JSON.stringify(params), headers);
}
-export function httpPut(url: string, params: object = {}, headers: object = {}) {
+export async function httpPut(url: string, params: object = {}, headers: object = {}) {
return request('PUT', url, JSON.stringify(params), headers);
}