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