All files / Bandstand/src/app/bands/manage page.tsx

0% Statements 0/31
0% Branches 0/1
0% Functions 0/1
0% Lines 0/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                         
export const dynamic = 'force-dynamic'
 
import {prisma} from '@/lib/db'
import {pageOwner} from '@/lib/guard'
import ManageBands from '@/components/ManageBands'
 
export const metadata = {title: 'All bands'}
 
/** The install owner's page: every band, and the web addresses they use. */
export default async function ManageBandsPage() {
  const {user} = await pageOwner()
  const bands = await prisma.band.findMany({
    orderBy: {name: 'asc'},
    select: {
      id: true,
      name: true,
      appName: true,
      domains: {select: {host: true}, orderBy: {host: 'asc'}},
      memberships: {where: {userId: user.id}, select: {isAdmin: true}},
      _count: {select: {memberships: true, songs: true}},
    },
  })
  return (
    <ManageBands
      bands={bands.map((b) => ({
        id: b.id,
        name: b.name,
        appName: b.appName,
        domains: b.domains.map((d) => d.host),
        members: b._count.memberships,
        songs: b._count.songs,
        mine: b.memberships.length > 0,
      }))}
    />
  )
}