54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { prisma } from '@/lib/prisma'
|
|
import { requireAuth } from '@/lib/auth'
|
|
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
const user = await requireAuth()
|
|
const { id } = await params
|
|
|
|
// Check if user owns this artist
|
|
const artist = await prisma.artist.findUnique({
|
|
where: { id },
|
|
select: { userId: true },
|
|
})
|
|
|
|
if (!artist) {
|
|
return NextResponse.json({ error: 'Artist not found' }, { status: 404 })
|
|
}
|
|
|
|
if (artist.userId !== user.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 403 })
|
|
}
|
|
|
|
const invitations = await prisma.labelInvitation.findMany({
|
|
where: { artistId: id },
|
|
include: {
|
|
label: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
slug: true,
|
|
logoUrl: true,
|
|
description: true,
|
|
},
|
|
},
|
|
},
|
|
orderBy: {
|
|
createdAt: 'desc',
|
|
},
|
|
})
|
|
|
|
return NextResponse.json(invitations)
|
|
} catch (error) {
|
|
if (error instanceof Error && error.message === 'Unauthorized') {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
console.error('Error fetching artist invitations:', error)
|
|
return NextResponse.json({ error: 'Failed to fetch artist invitations' }, { status: 500 })
|
|
}
|
|
}
|