Skip to content

Commit

Permalink
Fix bug for missing project for new user
Browse files Browse the repository at this point in the history
  • Loading branch information
sarimrmalik committed Jan 29, 2024
1 parent 3e55536 commit a0b0b61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {PrismaClient} from '@prisma/client'
import env from './env.mjs'

declare global {
var prisma: PrismaClient | undefined
}

const prisma = global.prisma || new PrismaClient()

if (env.NODE_ENV === 'development') global.prisma = prisma
Expand Down
18 changes: 13 additions & 5 deletions lib/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,29 @@ export async function handleInstall({
// Get user & request to add project
const user = await prisma.user.findUnique({
where: {userName: userName},
include: {
select: {
id: true,
addProject: {
take: 1,
orderBy: {createdAt: 'desc'}
}
}
})

if (!user?.id)
return new Response(`Could not find user ${userName}`, {
status: 500
})

// Create projects
const projects = await prisma.project.createMany({
data: repositories.map((repo: Repository) => ({
name: repo.name,
slug: repo.name,
teamId: user.addProject[0].teamId ?? '',
createdBy: user.id
}))
createdBy: user.id,
teamId: user.addProject[0].teamId ?? ''
})),
skipDuplicates: true
})

// Clone, vectorize, and save public code to database
Expand Down Expand Up @@ -352,8 +359,9 @@ export async function handleAddOrDeleteProjects({
}
}
})

if (!user?.id)
return new Response(`Could not find or create customer ${userName}`, {
return new Response(`Could not find user ${userName}`, {
status: 500
})

Expand Down

0 comments on commit a0b0b61

Please sign in to comment.