Files
gestion_projet/src/lib/notify.ts
T
2026-07-01 12:39:59 +02:00

36 lines
975 B
TypeScript

import { supa } from './supabase'
import { Pole, Profile, NotificationKind, memberPoles } from './types'
/**
* Crée une notification pour chaque membre du pôle destinataire
* (sauf l'auteur de l'action). Utilisé lorsqu'une tâche ou un bug
* est confié à un pôle.
*/
export async function notifyPole(opts: {
projectId: string
pole: Pole
kind: NotificationKind
title: string // ex : « Nouvelle tâche »
body: string // titre de la tâche / du bug
entityId: string
actorId: string | null
members: Profile[]
}): Promise<void> {
const recipients = opts.members.filter(
(m) => memberPoles(m).includes(opts.pole) && m.id !== opts.actorId
)
if (recipients.length === 0) return
const rows = recipients.map((m) => ({
user_id: m.id,
project_id: opts.projectId,
kind: opts.kind,
title: opts.title,
body: opts.body,
entity_id: opts.entityId,
pole: opts.pole
}))
await supa().from('notifications').insert(rows)
}