56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { prisma } from '@/lib/prisma'
|
|
import { requireAuth } from '@/lib/auth'
|
|
|
|
export async function DELETE(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string; artistId: string }> }
|
|
) {
|
|
try {
|
|
const user = await requireAuth()
|
|
const { id, artistId } = await params
|
|
|
|
// Check if user owns this label
|
|
const label = await prisma.label.findUnique({
|
|
where: { id },
|
|
select: { userId: true },
|
|
})
|
|
|
|
if (!label) {
|
|
return NextResponse.json({ error: 'Label not found' }, { status: 404 })
|
|
}
|
|
|
|
if (label.userId !== user.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 403 })
|
|
}
|
|
|
|
// Check if artist exists and belongs to this label
|
|
const artist = await prisma.artist.findUnique({
|
|
where: { id: artistId },
|
|
select: { labelId: true },
|
|
})
|
|
|
|
if (!artist) {
|
|
return NextResponse.json({ error: 'Artist not found' }, { status: 404 })
|
|
}
|
|
|
|
if (artist.labelId !== id) {
|
|
return NextResponse.json({ error: 'Artist does not belong to this label' }, { status: 400 })
|
|
}
|
|
|
|
// Remove artist from label
|
|
await prisma.artist.update({
|
|
where: { id: artistId },
|
|
data: { labelId: null },
|
|
})
|
|
|
|
return NextResponse.json({ message: 'Artist removed from label successfully' })
|
|
} catch (error) {
|
|
if (error instanceof Error && error.message === 'Unauthorized') {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
console.error('Error removing artist from label:', error)
|
|
return NextResponse.json({ error: 'Failed to remove artist from label' }, { status: 500 })
|
|
}
|
|
}
|