All files / Bandstand/src/lib rehearsal-events.ts

22.72% Statements 5/22
0% Branches 0/1
0% Functions 0/1
22.72% Lines 5/22

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 38  1x   1x 1x 1x           1x                                                    
import type {CalEvent} from './ics'
import {keyOf} from './availability'
 
export const SITE = (
  process.env.NEXTAUTH_URL ?? 'http://localhost:3000'
).replace(/\/$/, '')
 
/**
 * One rehearsal as a calendar event. `site` is the band's own address, so
 * the links in it open the right band's pages.
 */
export function rehearsalEvent(
  r: {
    id: string
    date: Date
    time: string | null
    place: string | null
    note: string | null
  },
  band: {name: string; timezone: string},
  site: string = SITE,
): CalEvent {
  return {
    // The suffix predates multi-band; changing it would duplicate events
    // already in people's calendars
    uid: `rehearsal-${r.id}@monkeewrench`,
    date: keyOf(r.date),
    time: r.time,
    title: `${band.name} rehearsal`,
    location: r.place,
    description: [r.note, `Charts and setlists: ${site}/setlists`]
      .filter(Boolean)
      .join('\n'),
    url: `${site}/rehearsals`,
    tz: band.timezone,
  }
}