workshop-timezone.ts 985 B

12345678910111213141516171819202122232425
  1. import { SETTING_KEYS } from '@/features/settings/Schema/settingsSchema'
  2. import { db } from '@/lib/db'
  3. import { resolveWorkshopTimeZone } from '@/lib/timezone'
  4. export { resolveWorkshopTimeZone }
  5. /**
  6. * The zone server code reads workshop times in.
  7. *
  8. * The localisation page offers "automatic", which the browser resolves and
  9. * the server cannot. Saving that page also stores what the browser resolved,
  10. * so a workshop that never chose a zone still gets the right one here rather
  11. * than UTC. An explicit choice always wins.
  12. */
  13. export async function workshopTimeZone(organizationId: string): Promise<string> {
  14. const rows = await db.appSetting.findMany({
  15. where: { organizationId, key: { in: [SETTING_KEYS.TIMEZONE, SETTING_KEYS.TIMEZONE_DETECTED] } },
  16. select: { key: true, value: true },
  17. })
  18. const map = new Map(rows.map((r) => [r.key, r.value]))
  19. return resolveWorkshopTimeZone(
  20. map.get(SETTING_KEYS.TIMEZONE),
  21. map.get(SETTING_KEYS.TIMEZONE_DETECTED)
  22. )
  23. }