add fk(orgId) for all create

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-16 22:21:13 +02:00
parent 1fc64ef1f9
commit 4f9c624d08
8 changed files with 12 additions and 3 deletions

View File

@@ -32,7 +32,7 @@ async function getProjectId(
const project = await db.project.findUnique({ const project = await db.project.findUnique({
where: { where: {
organizationSlug: request.client?.organizationSlug, organizationId: request.client?.organizationSlug,
id: projectId, id: projectId,
}, },
}); });

View File

@@ -50,6 +50,7 @@ export async function POST(request: Request) {
.filter((a) => typeof a === 'string') .filter((a) => typeof a === 'string')
.map((projectId) => ({ .map((projectId) => ({
organizationSlug: membership.organizationId, organizationSlug: membership.organizationId,
organizationId: membership.organizationId,
projectId: projectId, projectId: projectId,
userId: user.id, userId: user.id,
level: AccessLevel.read, level: AccessLevel.read,
@@ -67,6 +68,7 @@ export async function POST(request: Request) {
.filter((a): a is string => typeof a === 'string') .filter((a): a is string => typeof a === 'string')
.map((projectId) => ({ .map((projectId) => ({
organizationSlug: payload.data.organization.slug, organizationSlug: payload.data.organization.slug,
organizationId: payload.data.organization.slug,
projectId: projectId, projectId: projectId,
userId: payload.data.public_user_data.user_id, userId: payload.data.public_user_data.user_id,
level: AccessLevel.read, level: AccessLevel.read,

View File

@@ -41,6 +41,7 @@ export const clientRouter = createTRPCRouter({
const secret = randomUUID(); const secret = randomUUID();
const data: Prisma.ClientCreateArgs['data'] = { const data: Prisma.ClientCreateArgs['data'] = {
organizationSlug: input.organizationSlug, organizationSlug: input.organizationSlug,
organizationId: input.organizationSlug,
projectId: input.projectId, projectId: input.projectId,
name: input.name, name: input.name,
type: input.type ?? 'write', type: input.type ?? 'write',

View File

@@ -30,6 +30,7 @@ export const dashboardRouter = createTRPCRouter({
id: await getId('dashboard', name), id: await getId('dashboard', name),
projectId: projectId, projectId: projectId,
organizationSlug: organizationSlug, organizationSlug: organizationSlug,
organizationId: organizationSlug,
name, name,
}, },
}); });

View File

@@ -52,6 +52,7 @@ export const onboardingRouter = createTRPCRouter({
id: await getId('project', input.project), id: await getId('project', input.project),
name: input.project, name: input.project,
organizationSlug: organization.id, organizationSlug: organization.id,
organizationId: organization.id,
types, types,
}, },
}); });
@@ -61,6 +62,7 @@ export const onboardingRouter = createTRPCRouter({
data: { data: {
name: `${project.name} Client`, name: `${project.name} Client`,
organizationSlug: organization.id, organizationSlug: organization.id,
organizationId: organization.id,
projectId: project.id, projectId: project.id,
type: 'write', type: 'write',
cors: input.domain ? stripTrailingSlash(input.domain) : null, cors: input.domain ? stripTrailingSlash(input.domain) : null,

View File

@@ -98,7 +98,7 @@ export const organizationRouter = createTRPCRouter({
db.projectAccess.deleteMany({ db.projectAccess.deleteMany({
where: { where: {
userId: input.userId, userId: input.userId,
organizationSlug: input.organizationId, organizationId: input.organizationId,
}, },
}), }),
]); ]);
@@ -117,13 +117,14 @@ export const organizationRouter = createTRPCRouter({
db.projectAccess.deleteMany({ db.projectAccess.deleteMany({
where: { where: {
userId: input.userId, userId: input.userId,
organizationSlug: input.organizationSlug, organizationId: input.organizationSlug,
}, },
}), }),
db.projectAccess.createMany({ db.projectAccess.createMany({
data: input.access.map((projectId) => ({ data: input.access.map((projectId) => ({
userId: input.userId, userId: input.userId,
organizationSlug: input.organizationSlug, organizationSlug: input.organizationSlug,
organizationId: input.organizationSlug,
projectId: projectId, projectId: projectId,
level: 'read', level: 'read',
})), })),

View File

@@ -45,6 +45,7 @@ export const projectRouter = createTRPCRouter({
data: { data: {
id: await getId('project', name), id: await getId('project', name),
organizationSlug: organizationSlug, organizationSlug: organizationSlug,
organizationId: organizationSlug,
name: name, name: name,
}, },
}); });

View File

@@ -18,6 +18,7 @@ export const shareRouter = createTRPCRouter({
create: { create: {
id: uid.rnd(), id: uid.rnd(),
organizationSlug: input.organizationSlug, organizationSlug: input.organizationSlug,
organizationId: input.organizationSlug,
projectId: input.projectId, projectId: input.projectId,
public: input.public, public: input.public,
password: input.password || null, password: input.password || null,