fix skip onboarding if no orgs/projects

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-07-11 23:32:15 +02:00
parent 2e037ca16d
commit 601c2264a2
5 changed files with 69 additions and 10 deletions

View File

@@ -2,7 +2,14 @@ import crypto from 'crypto';
import type { z } from 'zod';
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
import { db, getId, getOrganizationBySlug, getUserById } from '@openpanel/db';
import {
db,
getCurrentOrganizations,
getCurrentProjects,
getId,
getOrganizationBySlug,
getUserById,
} from '@openpanel/db';
import type { ProjectType } from '@openpanel/db';
import { zOnboardingProject } from '@openpanel/validation';
@@ -30,6 +37,35 @@ async function createOrGetOrganization(
}
export const onboardingRouter = createTRPCRouter({
skipOnboardingCheck: protectedProcedure.query(async ({ ctx }) => {
const members = await db.member.findMany({
where: {
userId: ctx.session.userId,
},
});
if (members.length > 0) {
return {
canSkip: true,
url: `/${members[0]?.organizationId}`,
};
}
const projectAccess = await db.projectAccess.findMany({
where: {
userId: ctx.session.userId,
},
});
if (projectAccess.length > 0) {
return {
canSkip: true,
url: `/${projectAccess[0]?.organizationId}/${projectAccess[0]?.projectId}`,
};
}
return { canSkip: false, url: null };
}),
project: protectedProcedure
.input(zOnboardingProject)
.mutation(async ({ input, ctx }) => {