Converted reports and share routes.

This commit is contained in:
Mike Cao 2025-01-28 10:21:56 -08:00
parent dcac7b7c96
commit 6c9f1ad06b
23 changed files with 574 additions and 5 deletions

View file

@ -243,7 +243,7 @@ async function pagedQuery<T>(model: string, criteria: T, pageParams: PageParams)
const data = await prisma.client[model].findMany({
...criteria,
...{
...(size > 0 && { take: +size, skip: +size * (page - 1) }),
...(size > 0 && { take: +size, skip: +size * (+page - 1) }),
...(orderBy && {
orderBy: [
{
@ -266,7 +266,7 @@ async function pagedRawQuery(
) {
const { page = 1, pageSize, orderBy, sortDescending = false } = pageParams;
const size = +pageSize || DEFAULT_PAGE_SIZE;
const offset = +size * (page - 1);
const offset = +size * (+page - 1);
const direction = sortDescending ? 'desc' : 'asc';
const statements = [

View file

@ -30,7 +30,17 @@ export const unitParam = z.string().refine(value => UNIT_TYPES.includes(value),
message: 'Invalid unit',
});
export const roleParam = z.string().regex(/team-member|team-view-only|team-manager/);
export const roleParam = z.enum(['team-member', 'team-view-only', 'team-manager']);
export const reportTypeParam = z.enum([
'funnel',
'insights',
'retention',
'utm',
'goals',
'journey',
'revenue',
]);
export const filterParams = {
url: z.string().optional(),

View file

@ -26,8 +26,8 @@ export type ReportType = ObjectValues<typeof REPORT_TYPES>;
export interface PageParams {
search?: string;
page?: number;
pageSize?: number;
page?: string;
pageSize?: string;
orderBy?: string;
sortDescending?: boolean;
}