Rebuild as InnungsApp project: replace stadtwerke analysis with full documentation
- PRD: vollständige Produktspezifikation (5 Module, Scope, Akzeptanzkriterien) - ARCHITECTURE: Tech Stack, Ordnerstruktur, Multi-Tenancy, Push, Kosten - DATABASE_SCHEMA: Vollständiges SQL-Schema mit RLS Policies und Views - USER_STORIES: 40+ Stories nach Rolle (Admin, Mitglied, Azubi, Obermeister) - PERSONAS: 5 detaillierte Nutzerprofile mit Alltag, Zitaten und Erwartungen - BUSINESS_MODEL: Preistabellen, Unit Economics, Revenue-Projektionen, Distribution - ROADMAP: 6 Phasen, Sprint-Planung, Meilensteine und KPIs - COMPETITIVE_ANALYSIS: Wettbewerbsmatrix, USPs, Preispositionierung - API_DESIGN: Supabase Query Patterns, Edge Functions, Realtime Subscriptions - ONBOARDING_FLOWS: 7 User Flows von Setup bis Fehlerfall - GTM_STRATEGY: 3-Phasen-Vertrieb, Outreach-Sequenz, Einwandbehandlung - AZUBI_MODULE: Video-Feed, 1-Click-Apply, Chat, Berichtsheft, Quiz - DSGVO_KONZEPT: Rechtsgrundlagen, TOMs, AVV, Minderjährige, Incident Response - FEATURES_BACKLOG: 72 Features nach MoSCoW + Technische Schulden Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
45
innungsapp/apps/admin/lib/notifications.ts
Normal file
45
innungsapp/apps/admin/lib/notifications.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { prisma } from '@innungsapp/shared'
|
||||
|
||||
const EXPO_PUSH_URL = 'https://exp.host/--/api/v2/push/send'
|
||||
|
||||
/**
|
||||
* Send push notifications to all active members in an org who have a push token
|
||||
*/
|
||||
export async function sendPushNotifications(orgId: string, title: string, body?: string) {
|
||||
const members = await prisma.member.findMany({
|
||||
where: { orgId, status: 'aktiv', pushToken: { not: null } },
|
||||
select: { pushToken: true },
|
||||
})
|
||||
|
||||
const tokens = members
|
||||
.map((m) => m.pushToken)
|
||||
.filter((t): t is string => t !== null)
|
||||
|
||||
if (tokens.length === 0) return
|
||||
|
||||
// Expo Push API supports batches of up to 100
|
||||
const batches: string[][] = []
|
||||
for (let i = 0; i < tokens.length; i += 100) {
|
||||
batches.push(tokens.slice(i, i + 100))
|
||||
}
|
||||
|
||||
for (const batch of batches) {
|
||||
const messages = batch.map((token) => ({
|
||||
to: token,
|
||||
title,
|
||||
body: body ?? 'Neue Nachricht von Ihrer Innung',
|
||||
sound: 'default',
|
||||
data: { type: 'news' },
|
||||
}))
|
||||
|
||||
await fetch(EXPO_PUSH_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Accept-encoding': 'gzip, deflate',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(messages),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user