rename all db columns

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-04-08 21:25:32 +02:00
parent 95b93b5f3a
commit 097ea18320
30 changed files with 303 additions and 232 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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