Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/danielroe/unsight.dev. Detect duplicate GitHub issues, areas of concern and more across related rep unsight.dev
ai clustering github machine-learning
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import { inArray } from 'drizzle-orm'
export default defineEventHandler(async (event) => { const session = await requireUserSession(event)
const body = await readBody<{ name: string, repos: string[] }>(event) if (!body.name?.trim()) { throw createError({ statusCode: 400, message: 'Dashboard name is required' }) } if (!body.repos?.length) { throw createError({ statusCode: 400, message: 'At least one repository is required' }) }
const drizzle = useDrizzle() const slug = slugify(body.name)
// Check for slug uniqueness within this user's dashboards const existing = await drizzle .select({ id: tables.dashboards.id }) .from(tables.dashboards) .where(and( eq(tables.dashboards.githubId, session.user.githubId), eq(tables.dashboards.slug, slug), )) .get()
if (existing) { throw createError({ statusCode: 409, message: 'A dashboard with this name already exists' }) }
// Resolve repo full_names to repo IDs const repoRecords = await drizzle .select({ id: tables.repos.id, fullName: tables.repos.full_name }) .from(tables.repos) .where(inArray(tables.repos.full_name, body.repos.map(r => r.toLowerCase())))
if (!repoRecords.length) { throw createError({ statusCode: 400, message: 'None of the specified repositories are indexed' }) }
const dashboardId = generateDashboardId()
await drizzle.insert(tables.dashboards).values({ id: dashboardId, slug, name: body.name.trim(), githubId: session.user.githubId, githubLogin: session.user.login, createdAt: Date.now(), })
// Insert repo associations await drizzle.insert(tables.dashboardRepos).values( repoRecords.map(r => ({ dashboardId, repoId: r.id, })), )
return { id: dashboardId, slug }})