rename all db columns
This commit is contained in:
@@ -89,5 +89,5 @@ export async function validateSdkRequest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.project_id;
|
return client.projectId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { Widget } from '@/components/widget';
|
|
||||||
import { escape } from 'sqlstring';
|
import { escape } from 'sqlstring';
|
||||||
|
|
||||||
import { db, getEvents } from '@openpanel/db';
|
import { db, getEvents } from '@openpanel/db';
|
||||||
@@ -12,7 +11,7 @@ interface Props {
|
|||||||
export default async function EventConversionsListServer({ projectId }: Props) {
|
export default async function EventConversionsListServer({ projectId }: Props) {
|
||||||
const conversions = await db.eventMeta.findMany({
|
const conversions = await db.eventMeta.findMany({
|
||||||
where: {
|
where: {
|
||||||
project_id: projectId,
|
projectId,
|
||||||
conversion: true,
|
conversion: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ export default function LayoutMenu({ dashboards }: LayoutMenuProps) {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
href={`/${item.organization_slug}/${item.project_id}/dashboards/${item.id}`}
|
href={`/${item.organizationSlug}/${item.projectId}/dashboards/${item.id}`}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import OverviewTopGeo from '@/components/overview/overview-top-geo';
|
|||||||
import OverviewTopPages from '@/components/overview/overview-top-pages';
|
import OverviewTopPages from '@/components/overview/overview-top-pages';
|
||||||
import OverviewTopSources from '@/components/overview/overview-top-sources';
|
import OverviewTopSources from '@/components/overview/overview-top-sources';
|
||||||
|
|
||||||
import { db } from '@openpanel/db';
|
import { getShareByProjectId } from '@openpanel/db';
|
||||||
|
|
||||||
import OverviewMetrics from '../../../../components/overview/overview-metrics';
|
import OverviewMetrics from '../../../../components/overview/overview-metrics';
|
||||||
import { StickyBelowHeader } from './layout-sticky-below-header';
|
import { StickyBelowHeader } from './layout-sticky-below-header';
|
||||||
@@ -26,11 +26,7 @@ interface PageProps {
|
|||||||
export default async function Page({
|
export default async function Page({
|
||||||
params: { organizationId, projectId },
|
params: { organizationId, projectId },
|
||||||
}: PageProps) {
|
}: PageProps) {
|
||||||
const share = await db.shareOverview.findUnique({
|
const share = await getShareByProjectId(projectId);
|
||||||
where: {
|
|
||||||
project_id: projectId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageLayout title="Overview" organizationSlug={organizationId}>
|
<PageLayout title="Overview" organizationSlug={organizationId}>
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export default function ListProjects({ projects, clients }: ListProjectsProps) {
|
|||||||
<Accordion type="single" collapsible className="-mx-4">
|
<Accordion type="single" collapsible className="-mx-4">
|
||||||
{projects.map((project) => {
|
{projects.map((project) => {
|
||||||
const pClients = clients.filter(
|
const pClients = clients.filter(
|
||||||
(client) => client.project_id === project.id
|
(client) => client.projectId === project.id
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<AccordionItem
|
<AccordionItem
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export default async function Page({
|
|||||||
}: PageProps) {
|
}: PageProps) {
|
||||||
const references = await getReferences({
|
const references = await getReferences({
|
||||||
where: {
|
where: {
|
||||||
project_id: projectId,
|
projectId,
|
||||||
},
|
},
|
||||||
take: 50,
|
take: 50,
|
||||||
skip: 0,
|
skip: 0,
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ export default async function Page({ params: { id } }: PageProps) {
|
|||||||
if (!share.public) {
|
if (!share.public) {
|
||||||
return notFound();
|
return notFound();
|
||||||
}
|
}
|
||||||
const projectId = share.project_id;
|
const projectId = share.projectId;
|
||||||
const organization = await getOrganizationBySlug(share.organization_slug);
|
const organization = await getOrganizationBySlug(share.organizationSlug);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-gradient-to-tl from-blue-950 to-blue-600 p-4 md:p-16">
|
<div className="bg-gradient-to-tl from-blue-950 to-blue-600 p-4 md:p-16">
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ export async function POST(request: Request) {
|
|||||||
data: access
|
data: access
|
||||||
.filter((a): a is string => typeof a === 'string')
|
.filter((a): a is string => typeof a === 'string')
|
||||||
.map((projectId) => ({
|
.map((projectId) => ({
|
||||||
organization_slug: payload.data.organization.slug!,
|
organizationSlug: payload.data.organization.slug!,
|
||||||
project_id: projectId,
|
projectId: projectId,
|
||||||
user_id: payload.data.public_user_data.user_id,
|
userId: payload.data.public_user_data.user_id,
|
||||||
level: AccessLevel.read,
|
level: AccessLevel.read,
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
@@ -23,8 +23,8 @@ export async function POST(request: Request) {
|
|||||||
if (payload.type === 'organizationMembership.deleted') {
|
if (payload.type === 'organizationMembership.deleted') {
|
||||||
await db.projectAccess.deleteMany({
|
await db.projectAccess.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
organization_slug: payload.data.organization.slug!,
|
organizationSlug: payload.data.organization.slug!,
|
||||||
user_id: payload.data.public_user_data.user_id,
|
userId: payload.data.public_user_data.user_id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ export function OverviewShare({ data }: OverviewShareProps) {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
mutation.mutate({
|
mutation.mutate({
|
||||||
public: false,
|
public: false,
|
||||||
projectId: data?.project_id,
|
projectId: data?.projectId,
|
||||||
organizationId: data?.organization_slug,
|
organizationId: data?.organizationSlug,
|
||||||
password: null,
|
password: null,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ import { popModal } from '..';
|
|||||||
|
|
||||||
interface ModalContentProps {
|
interface ModalContentProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ModalContent({ children }: ModalContentProps) {
|
export function ModalContent({ children, className }: ModalContentProps) {
|
||||||
return <DialogContent>{children}</DialogContent>;
|
return <DialogContent className={className}>{children}</DialogContent>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ModalHeaderProps {
|
interface ModalHeaderProps {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { createTRPCRouter, protectedProcedure } from '@/trpc/api/trpc';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
|
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
|
||||||
import { db, transformClient } from '@openpanel/db';
|
import { db } from '@openpanel/db';
|
||||||
|
|
||||||
export const clientRouter = createTRPCRouter({
|
export const clientRouter = createTRPCRouter({
|
||||||
list: protectedProcedure
|
list: protectedProcedure
|
||||||
@@ -15,7 +15,7 @@ export const clientRouter = createTRPCRouter({
|
|||||||
.query(async ({ input: { organizationId } }) => {
|
.query(async ({ input: { organizationId } }) => {
|
||||||
return db.client.findMany({
|
return db.client.findMany({
|
||||||
where: {
|
where: {
|
||||||
organization_slug: organizationId,
|
organizationSlug: organizationId,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
project: true,
|
project: true,
|
||||||
@@ -67,8 +67,8 @@ export const clientRouter = createTRPCRouter({
|
|||||||
const secret = randomUUID();
|
const secret = randomUUID();
|
||||||
const client = await db.client.create({
|
const client = await db.client.create({
|
||||||
data: {
|
data: {
|
||||||
organization_slug: input.organizationId,
|
organizationSlug: input.organizationId,
|
||||||
project_id: input.projectId,
|
projectId: input.projectId,
|
||||||
name: input.name,
|
name: input.name,
|
||||||
secret: input.cors ? null : await hashPassword(secret),
|
secret: input.cors ? null : await hashPassword(secret),
|
||||||
cors: input.cors ? stripTrailingSlash(input.cors) : '*',
|
cors: input.cors ? stripTrailingSlash(input.cors) : '*',
|
||||||
@@ -76,7 +76,7 @@ export const clientRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...transformClient(client),
|
...client,
|
||||||
secret: input.cors ? null : secret,
|
secret: input.cors ? null : secret,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ export const dashboardRouter = createTRPCRouter({
|
|||||||
return db.dashboard.create({
|
return db.dashboard.create({
|
||||||
data: {
|
data: {
|
||||||
id: await getId('dashboard', name),
|
id: await getId('dashboard', name),
|
||||||
project_id: projectId,
|
projectId: projectId,
|
||||||
organization_slug: organizationSlug,
|
organizationSlug: organizationSlug,
|
||||||
name,
|
name,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -63,7 +63,7 @@ export const dashboardRouter = createTRPCRouter({
|
|||||||
if (forceDelete) {
|
if (forceDelete) {
|
||||||
await db.report.deleteMany({
|
await db.report.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
dashboard_id: id,
|
dashboardId: id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ export const eventRouter = createTRPCRouter({
|
|||||||
.mutation(({ input: { projectId, name, icon, color, conversion } }) => {
|
.mutation(({ input: { projectId, name, icon, color, conversion } }) => {
|
||||||
return db.eventMeta.upsert({
|
return db.eventMeta.upsert({
|
||||||
where: {
|
where: {
|
||||||
name_project_id: {
|
name_projectId: {
|
||||||
name,
|
name,
|
||||||
project_id: projectId,
|
projectId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
create: { project_id: projectId, name, icon, color, conversion },
|
create: { projectId, name, icon, color, conversion },
|
||||||
update: { icon, color, conversion },
|
update: { icon, color, conversion },
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -4,12 +4,7 @@ import { clerkClient } from '@clerk/nextjs';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
|
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
|
||||||
import {
|
import { db, transformOrganization } from '@openpanel/db';
|
||||||
db,
|
|
||||||
transformClient,
|
|
||||||
transformOrganization,
|
|
||||||
transformProject,
|
|
||||||
} from '@openpanel/db';
|
|
||||||
|
|
||||||
export const onboardingRouter = createTRPCRouter({
|
export const onboardingRouter = createTRPCRouter({
|
||||||
organziation: protectedProcedure
|
organziation: protectedProcedure
|
||||||
@@ -30,7 +25,7 @@ export const onboardingRouter = createTRPCRouter({
|
|||||||
const project = await db.project.create({
|
const project = await db.project.create({
|
||||||
data: {
|
data: {
|
||||||
name: input.project,
|
name: input.project,
|
||||||
organization_slug: org.slug,
|
organizationSlug: org.slug,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -38,19 +33,19 @@ export const onboardingRouter = createTRPCRouter({
|
|||||||
const client = await db.client.create({
|
const client = await db.client.create({
|
||||||
data: {
|
data: {
|
||||||
name: `${project.name} Client`,
|
name: `${project.name} Client`,
|
||||||
organization_slug: org.slug,
|
organizationSlug: org.slug,
|
||||||
project_id: project.id,
|
projectId: project.id,
|
||||||
cors: input.cors ? stripTrailingSlash(input.cors) : '*',
|
cors: input.cors ? stripTrailingSlash(input.cors) : '*',
|
||||||
secret: input.cors ? null : await hashPassword(secret),
|
secret: input.cors ? null : await hashPassword(secret),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
client: transformClient({
|
client: {
|
||||||
...client,
|
...client,
|
||||||
secret: input.cors ? null : secret,
|
secret: input.cors ? null : secret,
|
||||||
}),
|
},
|
||||||
project: transformProject(project),
|
project,
|
||||||
organization: transformOrganization(org),
|
organization: transformOrganization(org),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,15 +77,15 @@ export const organizationRouter = createTRPCRouter({
|
|||||||
return db.$transaction([
|
return db.$transaction([
|
||||||
db.projectAccess.deleteMany({
|
db.projectAccess.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
user_id: input.userId,
|
userId: input.userId,
|
||||||
organization_slug: input.organizationSlug,
|
organizationSlug: input.organizationSlug,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
db.projectAccess.createMany({
|
db.projectAccess.createMany({
|
||||||
data: input.access.map((projectId) => ({
|
data: input.access.map((projectId) => ({
|
||||||
user_id: input.userId,
|
userId: input.userId,
|
||||||
organization_slug: input.organizationSlug,
|
organizationSlug: input.organizationSlug,
|
||||||
project_id: projectId,
|
projectId: projectId,
|
||||||
level: 'read',
|
level: 'read',
|
||||||
})),
|
})),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
return db.project.create({
|
return db.project.create({
|
||||||
data: {
|
data: {
|
||||||
id: await getId('project', input.name),
|
id: await getId('project', input.name),
|
||||||
organization_slug: input.organizationId,
|
organizationSlug: input.organizationId,
|
||||||
name: input.name,
|
name: input.name,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const referenceRouter = createTRPCRouter({
|
|||||||
data: {
|
data: {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
project_id: projectId,
|
projectId,
|
||||||
date: new Date(datetime),
|
date: new Date(datetime),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -47,7 +47,7 @@ export const referenceRouter = createTRPCRouter({
|
|||||||
const { startDate, endDate } = getChartStartEndDate(input);
|
const { startDate, endDate } = getChartStartEndDate(input);
|
||||||
return getReferences({
|
return getReferences({
|
||||||
where: {
|
where: {
|
||||||
project_id: projectId,
|
projectId,
|
||||||
date: {
|
date: {
|
||||||
gte: new Date(startDate),
|
gte: new Date(startDate),
|
||||||
lte: new Date(endDate),
|
lte: new Date(endDate),
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ export const reportRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
return db.report.create({
|
return db.report.create({
|
||||||
data: {
|
data: {
|
||||||
project_id: dashboard.project_id,
|
projectId: dashboard.projectId,
|
||||||
dashboard_id: dashboardId,
|
dashboardId,
|
||||||
name: report.name,
|
name: report.name,
|
||||||
events: report.events,
|
events: report.events,
|
||||||
interval: report.interval,
|
interval: report.interval,
|
||||||
breakdowns: report.breakdowns,
|
breakdowns: report.breakdowns,
|
||||||
chart_type: report.chartType,
|
chartType: report.chartType,
|
||||||
line_type: report.lineType,
|
lineType: report.lineType,
|
||||||
range: report.range,
|
range: report.range,
|
||||||
formula: report.formula,
|
formula: report.formula,
|
||||||
},
|
},
|
||||||
@@ -50,8 +50,8 @@ export const reportRouter = createTRPCRouter({
|
|||||||
events: report.events,
|
events: report.events,
|
||||||
interval: report.interval,
|
interval: report.interval,
|
||||||
breakdowns: report.breakdowns,
|
breakdowns: report.breakdowns,
|
||||||
chart_type: report.chartType,
|
chartType: report.chartType,
|
||||||
line_type: report.lineType,
|
lineType: report.lineType,
|
||||||
range: report.range,
|
range: report.range,
|
||||||
formula: report.formula,
|
formula: report.formula,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ export const shareRouter = createTRPCRouter({
|
|||||||
.mutation(({ input }) => {
|
.mutation(({ input }) => {
|
||||||
return db.shareOverview.upsert({
|
return db.shareOverview.upsert({
|
||||||
where: {
|
where: {
|
||||||
project_id: input.projectId,
|
projectId: input.projectId,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
id: uid.rnd(),
|
id: uid.rnd(),
|
||||||
organization_slug: input.organizationId,
|
organizationSlug: input.organizationId,
|
||||||
project_id: input.projectId,
|
projectId: input.projectId,
|
||||||
public: input.public,
|
public: input.public,
|
||||||
password: input.password || null,
|
password: input.password || null,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
-- Project
|
||||||
|
-- organization_slug -> organizationSlug
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "projects" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||||
|
|
||||||
|
-- ProjectAccess
|
||||||
|
-- project_id -> projectId
|
||||||
|
-- organization_slug -> organizationSlug
|
||||||
|
-- user_id -> userId
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "project_access" RENAME COLUMN "project_id" TO "projectId";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "project_access" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "project_access" RENAME COLUMN "user_id" TO "userId";
|
||||||
|
|
||||||
|
-- Event
|
||||||
|
-- project_id -> projectId
|
||||||
|
-- profile_id -> profileId
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "events" RENAME COLUMN "project_id" TO "projectId";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "events" RENAME COLUMN "profile_id" TO "profileId";
|
||||||
|
|
||||||
|
-- Profile
|
||||||
|
-- external_id -> externalId
|
||||||
|
-- first_name -> firstName
|
||||||
|
-- last_name -> lastName
|
||||||
|
-- project_id -> projectId
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "profiles" RENAME COLUMN "external_id" TO "externalId";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "profiles" RENAME COLUMN "first_name" TO "firstName";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "profiles" RENAME COLUMN "last_name" TO "lastName";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "profiles" RENAME COLUMN "project_id" TO "projectId";
|
||||||
|
|
||||||
|
-- Client
|
||||||
|
-- project_id -> projectId
|
||||||
|
-- organization_slug -> organizationSlug
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "clients" RENAME COLUMN "project_id" TO "projectId";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "clients" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||||
|
|
||||||
|
-- Dashboard
|
||||||
|
-- organization_slug -> organizationSlug
|
||||||
|
-- project_id -> projectId
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "dashboards" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "dashboards" RENAME COLUMN "project_id" TO "projectId";
|
||||||
|
|
||||||
|
-- Report
|
||||||
|
-- chart_type -> chartType
|
||||||
|
-- line_type -> lineType
|
||||||
|
-- project_id -> projectId
|
||||||
|
-- dashboard_id -> dashboardId
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "reports" RENAME COLUMN "chart_type" TO "chartType";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "reports" RENAME COLUMN "line_type" TO "lineType";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "reports" RENAME COLUMN "project_id" TO "projectId";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "reports" RENAME COLUMN "dashboard_id" TO "dashboardId";
|
||||||
|
|
||||||
|
-- ShareOverview
|
||||||
|
-- project_id -> projectId
|
||||||
|
-- organization_slug -> organizationSlug
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "shares" RENAME COLUMN "project_id" TO "projectId";
|
||||||
|
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "shares" RENAME COLUMN "organization_slug" TO "organizationSlug";
|
||||||
|
|
||||||
|
-- EventMeta (ta bort constraint)
|
||||||
|
-- project_id -> projectId
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "event_meta" RENAME COLUMN "project_id" TO "projectId";
|
||||||
|
|
||||||
|
-- Reference
|
||||||
|
-- project_id -> projectId
|
||||||
|
ALTER TABLE
|
||||||
|
IF EXISTS "references" RENAME COLUMN "project_id" TO "projectId";
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "clients" RENAME CONSTRAINT "clients_project_id_fkey" TO "clients_projectId_fkey";
|
||||||
|
|
||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "dashboards" RENAME CONSTRAINT "dashboards_project_id_fkey" TO "dashboards_projectId_fkey";
|
||||||
|
|
||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "event_meta" RENAME CONSTRAINT "event_meta_project_id_fkey" TO "event_meta_projectId_fkey";
|
||||||
|
|
||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "events" RENAME CONSTRAINT "events_project_id_fkey" TO "events_projectId_fkey";
|
||||||
|
|
||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "profiles" RENAME CONSTRAINT "profiles_project_id_fkey" TO "profiles_projectId_fkey";
|
||||||
|
|
||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "project_access" RENAME CONSTRAINT "project_access_project_id_fkey" TO "project_access_projectId_fkey";
|
||||||
|
|
||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "references" RENAME CONSTRAINT "references_project_id_fkey" TO "references_projectId_fkey";
|
||||||
|
|
||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "reports" RENAME CONSTRAINT "reports_dashboard_id_fkey" TO "reports_dashboardId_fkey";
|
||||||
|
|
||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "reports" RENAME CONSTRAINT "reports_project_id_fkey" TO "reports_projectId_fkey";
|
||||||
|
|
||||||
|
-- RenameForeignKey
|
||||||
|
ALTER TABLE "shares" RENAME CONSTRAINT "shares_project_id_fkey" TO "shares_projectId_fkey";
|
||||||
|
|
||||||
|
-- RenameIndex
|
||||||
|
ALTER INDEX "event_meta_name_project_id_key" RENAME TO "event_meta_name_projectId_key";
|
||||||
|
|
||||||
|
-- RenameIndex
|
||||||
|
ALTER INDEX "shares_project_id_key" RENAME TO "shares_projectId_key";
|
||||||
@@ -11,23 +11,23 @@ datasource db {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Project {
|
model Project {
|
||||||
id String @id @default(dbgenerated("gen_random_uuid()"))
|
id String @id @default(dbgenerated("gen_random_uuid()"))
|
||||||
name String
|
name String
|
||||||
organization_slug String
|
organizationSlug String
|
||||||
events Event[]
|
eventsCount Int @default(0)
|
||||||
eventsCount Int @default(0)
|
|
||||||
profiles Profile[]
|
|
||||||
clients Client[]
|
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
events Event[]
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
profiles Profile[]
|
||||||
|
clients Client[]
|
||||||
reports Report[]
|
reports Report[]
|
||||||
dashboards Dashboard[]
|
dashboards Dashboard[]
|
||||||
share ShareOverview?
|
share ShareOverview?
|
||||||
EventMeta EventMeta[]
|
meta EventMeta[]
|
||||||
Reference Reference[]
|
references Reference[]
|
||||||
|
access ProjectAccess[]
|
||||||
|
|
||||||
access ProjectAccess[]
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|
||||||
@@map("projects")
|
@@map("projects")
|
||||||
}
|
}
|
||||||
@@ -39,14 +39,14 @@ enum AccessLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model ProjectAccess {
|
model ProjectAccess {
|
||||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||||
project_id String
|
projectId String
|
||||||
project Project @relation(fields: [project_id], references: [id])
|
project Project @relation(fields: [projectId], references: [id])
|
||||||
organization_slug String
|
organizationSlug String
|
||||||
user_id String
|
userId String
|
||||||
level AccessLevel
|
level AccessLevel
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|
||||||
@@map("project_access")
|
@@map("project_access")
|
||||||
}
|
}
|
||||||
@@ -55,10 +55,10 @@ model Event {
|
|||||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||||
name String
|
name String
|
||||||
properties Json
|
properties Json
|
||||||
project_id String
|
projectId String
|
||||||
project Project @relation(fields: [project_id], references: [id])
|
project Project @relation(fields: [projectId], references: [id])
|
||||||
|
|
||||||
profile_id String?
|
profileId String?
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
@@ -75,29 +75,29 @@ model Salt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Profile {
|
model Profile {
|
||||||
id String @id
|
id String @id
|
||||||
external_id String?
|
externalId String?
|
||||||
first_name String?
|
firstName String?
|
||||||
last_name String?
|
lastName String?
|
||||||
email String?
|
email String?
|
||||||
avatar String?
|
avatar String?
|
||||||
properties Json
|
properties Json
|
||||||
project_id String
|
projectId String
|
||||||
project Project @relation(fields: [project_id], references: [id])
|
project Project @relation(fields: [projectId], references: [id])
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|
||||||
@@map("profiles")
|
@@map("profiles")
|
||||||
}
|
}
|
||||||
|
|
||||||
model Client {
|
model Client {
|
||||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||||
name String
|
name String
|
||||||
secret String?
|
secret String?
|
||||||
project_id String
|
projectId String
|
||||||
project Project @relation(fields: [project_id], references: [id])
|
project Project @relation(fields: [projectId], references: [id])
|
||||||
organization_slug String
|
organizationSlug String
|
||||||
cors String @default("*")
|
cors String @default("*")
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
@@ -124,12 +124,12 @@ enum ChartType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Dashboard {
|
model Dashboard {
|
||||||
id String @id @default(dbgenerated("gen_random_uuid()"))
|
id String @id @default(dbgenerated("gen_random_uuid()"))
|
||||||
name String
|
name String
|
||||||
organization_slug String
|
organizationSlug String
|
||||||
project_id String
|
projectId String
|
||||||
project Project @relation(fields: [project_id], references: [id])
|
project Project @relation(fields: [projectId], references: [id])
|
||||||
reports Report[]
|
reports Report[]
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
@@ -149,19 +149,19 @@ model Report {
|
|||||||
name String
|
name String
|
||||||
interval Interval
|
interval Interval
|
||||||
range String @default("1m")
|
range String @default("1m")
|
||||||
chart_type ChartType
|
chartType ChartType
|
||||||
line_type String @default("monotone")
|
lineType String @default("monotone")
|
||||||
breakdowns Json
|
breakdowns Json
|
||||||
events Json
|
events Json
|
||||||
formula String?
|
formula String?
|
||||||
unit String?
|
unit String?
|
||||||
metric Metric @default(sum)
|
metric Metric @default(sum)
|
||||||
project_id String
|
projectId String
|
||||||
project Project @relation(fields: [project_id], references: [id])
|
project Project @relation(fields: [projectId], references: [id])
|
||||||
previous Boolean @default(false)
|
previous Boolean @default(false)
|
||||||
|
|
||||||
dashboard_id String
|
dashboardId String
|
||||||
dashboard Dashboard @relation(fields: [dashboard_id], references: [id])
|
dashboard Dashboard @relation(fields: [dashboardId], references: [id])
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
@@ -180,14 +180,14 @@ model Waitlist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model ShareOverview {
|
model ShareOverview {
|
||||||
id String @unique
|
id String @unique
|
||||||
project_id String @unique
|
projectId String @unique
|
||||||
project Project @relation(fields: [project_id], references: [id])
|
project Project @relation(fields: [projectId], references: [id])
|
||||||
organization_slug String
|
organizationSlug String
|
||||||
public Boolean @default(false)
|
public Boolean @default(false)
|
||||||
password String?
|
password String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|
||||||
@@map("shares")
|
@@map("shares")
|
||||||
}
|
}
|
||||||
@@ -198,13 +198,13 @@ model EventMeta {
|
|||||||
conversion Boolean?
|
conversion Boolean?
|
||||||
color String?
|
color String?
|
||||||
icon String?
|
icon String?
|
||||||
project_id String
|
projectId String
|
||||||
project Project @relation(fields: [project_id], references: [id])
|
project Project @relation(fields: [projectId], references: [id])
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|
||||||
@@unique([name, project_id])
|
@@unique([name, projectId])
|
||||||
@@map("event_meta")
|
@@map("event_meta")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,8 +213,8 @@ model Reference {
|
|||||||
title String
|
title String
|
||||||
description String?
|
description String?
|
||||||
date DateTime @default(now())
|
date DateTime @default(now())
|
||||||
project_id String
|
projectId String
|
||||||
project Project @relation(fields: [project_id], references: [id])
|
project Project @relation(fields: [projectId], references: [id])
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|||||||
@@ -1,38 +1,20 @@
|
|||||||
import type { Client } from '../prisma-client';
|
import type { Client, Prisma } from '../prisma-client';
|
||||||
import { db } from '../prisma-client';
|
import { db } from '../prisma-client';
|
||||||
import { transformProject } from './project.service';
|
|
||||||
import type { IServiceProject } from './project.service';
|
|
||||||
|
|
||||||
export type IServiceClient = ReturnType<typeof transformClient>;
|
export type IServiceClient = Client;
|
||||||
export type IServiceClientWithProject = IServiceClient & {
|
export type IServiceClientWithProject = Prisma.ClientGetPayload<{
|
||||||
project: Exclude<IServiceProject, null>;
|
include: {
|
||||||
};
|
project: true;
|
||||||
|
|
||||||
export function transformClient({ organization_slug, ...client }: Client) {
|
|
||||||
return {
|
|
||||||
...client,
|
|
||||||
organizationSlug: organization_slug,
|
|
||||||
};
|
};
|
||||||
}
|
}>;
|
||||||
|
|
||||||
export async function getClientsByOrganizationId(organizationId: string) {
|
export async function getClientsByOrganizationId(organizationId: string) {
|
||||||
const clients = await db.client.findMany({
|
return db.client.findMany({
|
||||||
where: {
|
where: {
|
||||||
organization_slug: organizationId,
|
organizationSlug: organizationId,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
project: true,
|
project: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return clients
|
|
||||||
.map((client) => {
|
|
||||||
return {
|
|
||||||
...transformClient(client),
|
|
||||||
project: transformProject(client.project),
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.filter(
|
|
||||||
(client): client is IServiceClientWithProject => client.project !== null
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
|
import type { Dashboard, Prisma } from '../prisma-client';
|
||||||
import { db } from '../prisma-client';
|
import { db } from '../prisma-client';
|
||||||
|
|
||||||
export type IServiceDashboard = Awaited<ReturnType<typeof getDashboardById>>;
|
export type IServiceDashboard = Dashboard;
|
||||||
export type IServiceDashboards = Awaited<
|
export type IServiceDashboards = Prisma.DashboardGetPayload<{
|
||||||
ReturnType<typeof getDashboardsByProjectId>
|
include: {
|
||||||
>;
|
project: true;
|
||||||
|
};
|
||||||
|
}>[];
|
||||||
|
|
||||||
export async function getDashboardById(id: string, projectId: string) {
|
export async function getDashboardById(id: string, projectId: string) {
|
||||||
const dashboard = await db.dashboard.findUnique({
|
const dashboard = await db.dashboard.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
project_id: projectId,
|
projectId,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
project: true,
|
project: true,
|
||||||
@@ -26,7 +29,7 @@ export async function getDashboardById(id: string, projectId: string) {
|
|||||||
export function getDashboardsByProjectId(projectId: string) {
|
export function getDashboardsByProjectId(projectId: string) {
|
||||||
return db.dashboard.findMany({
|
return db.dashboard.findMany({
|
||||||
where: {
|
where: {
|
||||||
project_id: projectId,
|
projectId,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
project: true,
|
project: true,
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ export async function getEvents(
|
|||||||
name: {
|
name: {
|
||||||
in: names,
|
in: names,
|
||||||
},
|
},
|
||||||
project_id: events[0]?.project_id,
|
projectId: events[0]?.project_id,
|
||||||
},
|
},
|
||||||
select: options.meta === true ? undefined : options.meta,
|
select: options.meta === true ? undefined : options.meta,
|
||||||
});
|
});
|
||||||
@@ -265,7 +265,7 @@ export async function getEventList({
|
|||||||
sb.where.projectId = `project_id = ${escape(projectId)}`;
|
sb.where.projectId = `project_id = ${escape(projectId)}`;
|
||||||
|
|
||||||
if (profileId) {
|
if (profileId) {
|
||||||
sb.where.deviceId = `device_id IN (SELECT device_id as did FROM openpanel.events WHERE profile_id = ${escape(profileId)} group by did)`;
|
sb.where.deviceId = `device_id IN (SELECT device_id as did FROM events WHERE profile_id = ${escape(profileId)} group by did)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events && events.length > 0) {
|
if (events && events.length > 0) {
|
||||||
@@ -357,7 +357,7 @@ export function createBotEvent({
|
|||||||
export function getConversionEventNames(projectId: string) {
|
export function getConversionEventNames(projectId: string) {
|
||||||
return db.eventMeta.findMany({
|
return db.eventMeta.findMany({
|
||||||
where: {
|
where: {
|
||||||
project_id: projectId,
|
projectId,
|
||||||
conversion: true,
|
conversion: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { db } from '../prisma-client';
|
|||||||
export type IServiceOrganization = ReturnType<typeof transformOrganization>;
|
export type IServiceOrganization = ReturnType<typeof transformOrganization>;
|
||||||
export type IServiceInvite = ReturnType<typeof transformInvite>;
|
export type IServiceInvite = ReturnType<typeof transformInvite>;
|
||||||
export type IServiceMember = ReturnType<typeof transformMember>;
|
export type IServiceMember = ReturnType<typeof transformMember>;
|
||||||
export type IServiceProjectAccess = ReturnType<typeof transformAccess>;
|
export type IServiceProjectAccess = ProjectAccess;
|
||||||
|
|
||||||
export function transformOrganization(org: Organization) {
|
export function transformOrganization(org: Organization) {
|
||||||
return {
|
return {
|
||||||
@@ -21,15 +21,6 @@ export function transformOrganization(org: Organization) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transformAccess(access: ProjectAccess) {
|
|
||||||
return {
|
|
||||||
projectId: access.project_id,
|
|
||||||
userId: access.user_id,
|
|
||||||
level: access.level,
|
|
||||||
organizationSlug: access.organization_slug,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getCurrentOrganizations() {
|
export async function getCurrentOrganizations() {
|
||||||
const session = auth();
|
const session = auth();
|
||||||
const organizations = await clerkClient.users.getOrganizationMembershipList({
|
const organizations = await clerkClient.users.getOrganizationMembershipList({
|
||||||
@@ -53,7 +44,7 @@ export async function getOrganizationByProjectId(projectId: string) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return clerkClient.organizations.getOrganization({
|
return clerkClient.organizations.getOrganization({
|
||||||
slug: project.organization_slug,
|
slug: project.organizationSlug,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +101,7 @@ export async function getMembers(organizationSlug: string) {
|
|||||||
}),
|
}),
|
||||||
db.projectAccess.findMany({
|
db.projectAccess.findMany({
|
||||||
where: {
|
where: {
|
||||||
organization_slug: organizationSlug,
|
organizationSlug,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
@@ -118,11 +109,11 @@ export async function getMembers(organizationSlug: string) {
|
|||||||
return members
|
return members
|
||||||
.map((member) => {
|
.map((member) => {
|
||||||
const projectAccess = access.filter(
|
const projectAccess = access.filter(
|
||||||
(item) => item.user_id === member.publicUserData?.userId
|
(item) => item.userId === member.publicUserData?.userId
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...member,
|
...member,
|
||||||
access: projectAccess.map(transformAccess),
|
access: projectAccess,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.map(transformMember);
|
.map(transformMember);
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
import { auth } from '@clerk/nextjs';
|
import { auth } from '@clerk/nextjs';
|
||||||
import { project } from 'ramda';
|
|
||||||
|
|
||||||
import type { Project } from '../prisma-client';
|
import type { Project } from '../prisma-client';
|
||||||
import { db } from '../prisma-client';
|
import { db } from '../prisma-client';
|
||||||
|
|
||||||
export type IServiceProject = ReturnType<typeof transformProject>;
|
export type IServiceProject = Project;
|
||||||
|
|
||||||
export function transformProject({ organization_slug, ...project }: Project) {
|
|
||||||
return {
|
|
||||||
organizationSlug: organization_slug,
|
|
||||||
...project,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getProjectById(id: string) {
|
export async function getProjectById(id: string) {
|
||||||
const res = await db.project.findUnique({
|
const res = await db.project.findUnique({
|
||||||
@@ -24,46 +16,32 @@ export async function getProjectById(id: string) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return transformProject(res);
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getProjectsByOrganizationSlug(slug: string) {
|
export async function getProjectsByOrganizationSlug(organizationSlug: string) {
|
||||||
const res = await db.project.findMany({
|
return db.project.findMany({
|
||||||
where: {
|
where: {
|
||||||
organization_slug: slug,
|
organizationSlug,
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: 'desc',
|
createdAt: 'desc',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.map(transformProject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCurrentProjects(slug: string) {
|
export async function getCurrentProjects(organizationSlug: string) {
|
||||||
const session = auth();
|
const session = auth();
|
||||||
if (!session.userId) {
|
if (!session.userId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const access = await db.projectAccess.findMany({
|
return db.project.findMany({
|
||||||
where: {
|
where: {
|
||||||
organization_slug: slug,
|
organizationSlug,
|
||||||
user_id: session.userId,
|
},
|
||||||
|
include: {
|
||||||
|
access: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await db.project.findMany({
|
|
||||||
where: {
|
|
||||||
organization_slug: slug,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (access.length === 0) {
|
|
||||||
return res.map(transformProject);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res
|
|
||||||
.filter((project) => access.some((a) => a.project_id === project.id))
|
|
||||||
.map(transformProject);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,7 @@
|
|||||||
import type { Prisma, Reference } from '../prisma-client';
|
import type { Prisma, Reference } from '../prisma-client';
|
||||||
import { db } from '../prisma-client';
|
import { db } from '../prisma-client';
|
||||||
|
|
||||||
export type IServiceReference = Omit<Reference, 'project_id'> & {
|
export type IServiceReference = Reference;
|
||||||
projectId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function transformReference({
|
|
||||||
project_id,
|
|
||||||
...item
|
|
||||||
}: Reference): IServiceReference {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
projectId: project_id,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getReferenceById(id: string) {
|
export async function getReferenceById(id: string) {
|
||||||
const reference = await db.reference.findUnique({
|
const reference = await db.reference.findUnique({
|
||||||
@@ -26,7 +14,7 @@ export async function getReferenceById(id: string) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return transformReference(reference);
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getReferences({
|
export async function getReferences({
|
||||||
@@ -38,11 +26,9 @@ export async function getReferences({
|
|||||||
take?: number;
|
take?: number;
|
||||||
skip?: number;
|
skip?: number;
|
||||||
}) {
|
}) {
|
||||||
const references = await db.reference.findMany({
|
return db.reference.findMany({
|
||||||
where,
|
where,
|
||||||
take: take ?? 50,
|
take: take ?? 50,
|
||||||
skip,
|
skip,
|
||||||
});
|
});
|
||||||
|
|
||||||
return references.map(transformReference);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ export function transformReport(
|
|||||||
): IChartInput & { id: string } {
|
): IChartInput & { id: string } {
|
||||||
return {
|
return {
|
||||||
id: report.id,
|
id: report.id,
|
||||||
projectId: report.project_id,
|
projectId: report.projectId,
|
||||||
events: (report.events as IChartEvent[]).map(transformReportEvent),
|
events: (report.events as IChartEvent[]).map(transformReportEvent),
|
||||||
breakdowns: report.breakdowns as IChartBreakdown[],
|
breakdowns: report.breakdowns as IChartBreakdown[],
|
||||||
chartType: report.chart_type,
|
chartType: report.chartType,
|
||||||
lineType: (report.line_type as IChartLineType) ?? lineTypes.monotone,
|
lineType: (report.lineType as IChartLineType) ?? lineTypes.monotone,
|
||||||
interval: report.interval,
|
interval: report.interval,
|
||||||
name: report.name || 'Untitled',
|
name: report.name || 'Untitled',
|
||||||
range: (report.range as IChartRange) ?? timeRanges['1m'],
|
range: (report.range as IChartRange) ?? timeRanges['1m'],
|
||||||
@@ -64,7 +64,7 @@ export function getReportsByDashboardId(dashboardId: string) {
|
|||||||
return db.report
|
return db.report
|
||||||
.findMany({
|
.findMany({
|
||||||
where: {
|
where: {
|
||||||
dashboard_id: dashboardId,
|
dashboardId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((reports) => reports.map(transformReport));
|
.then((reports) => reports.map(transformReport));
|
||||||
|
|||||||
@@ -10,3 +10,11 @@ export function getShareOverviewById(id: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getShareByProjectId(projectId: string) {
|
||||||
|
return db.shareOverview.findUnique({
|
||||||
|
where: {
|
||||||
|
projectId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user