Tipi RPC
Panoramica
Le RPC sono funzioni PostgreSQL esposte da PostgREST come endpoint POST /rpc/{nome}. Richiedono l'header Content-Profile: fasi.
sposta_scheda_fase
BR-003: usare SEMPRE questa RPC per spostare schede tra fasi. MAI PATCH /scheda?idscheda=eq.{id} diretto su idfase.
// Request
interface SpostaSchedaRequest {
p_idscheda: number
p_idfasedestinazione: number
p_idutente: number
}
// Response
interface SpostaSchedaResponse {
success: boolean
idscheda: number
faseorigine: {
idfase: number
nome: string
finale?: boolean
}
fasedestinazione: {
idfase: number
nome: string
finale?: boolean
}
notifiche_accodate: number // > 0 se fase con template email/SMS
datachiusura: string | null // valorizzata solo se fasedestinazione.finale = true
}
Notifiche
Se response.notifiche_accodate > 0, la fase destinazione ha template email o SMS configurati. Le notifiche vengono inviate asincronamente da un worker separato.
Chiusura automatica
Se fasedestinazione.finale: true, la scheda riceve una datachiusura (ISO 8601). Il campo è disponibile in SchedaKanban.datachisura dopo il refresh.
riordina_fasi
// Request
interface RiordinaFasiRequest {
p_fasi: Array<{ idfase: number; ordine: number }>
}
// Response
interface RiordinaFasiResponse {
success: boolean
}
Il payload p_fasi deve includere tutte le fasi della board con i nuovi valori ordine. La RPC è transazionale — aggiorna tutti i record in un'unica operazione.
calcola_schede_stallo
// Request (p_idfase opzionale — null = tutte le fasi)
interface CalcolaSchedeStalloRequest {
p_idfase?: number | null
}
// Response (array di righe)
interface SchedaInStallo {
idscheda: number
idfase: number
titolo: string
giorni_infase: number
giorni_oltre: number // giorni_infase - giornistallo
giornistallo: number
nome_fase: string
}
Normalmente non è necessario chiamare questa RPC manualmente — useFasiMetrics.loadStalli() usa la vista v_stalli_pipeline che calcola automaticamente.