Fixed queries again.

This commit is contained in:
Mike Cao 2025-02-06 11:22:00 -08:00
parent fc640ff394
commit 1ba28ece8b
8 changed files with 26 additions and 21 deletions

View file

@ -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) {

View file

@ -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);

View file

@ -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 }> }) {

View file

@ -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,

View file

@ -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();
}

View file

@ -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,

View file

@ -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);
},

View file

@ -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);
}