excluir paciente funcional

This commit is contained in:
Pedro Araujo da Silveira 2025-10-09 09:15:18 -03:00
parent e5f55c1f69
commit fc6acff393
2 changed files with 11 additions and 4 deletions

View File

@ -613,9 +613,14 @@ const PainelSecretaria = () => {
return;
}
try {
await deletePatient(paciente.id);
setPacientes((prev) => prev.filter((p) => p.id !== paciente.id));
toast.success("Paciente removido");
const resp = await deletePatient(paciente.id);
if (resp && resp.success) {
setPacientes((prev) => prev.filter((p) => p.id !== paciente.id));
toast.success("Paciente removido");
} else {
console.error("Falha ao remover paciente (API):", resp?.error);
toast.error(resp?.error || "Erro ao remover paciente");
}
} catch (error) {
console.error("Erro ao remover paciente:", error);
toast.error("Erro ao remover paciente");

View File

@ -535,8 +535,10 @@ export async function updatePatient(
export async function deletePatient(id: string): Promise<ApiResponse<void>> {
if (!id) return { success: false, error: "ID é obrigatório" };
try {
// PostgREST / Supabase REST geralmente usa filtros via query string (e.g. ?id=eq.{id})
// usar o padrão `?id=eq.{id}` para garantir compatibilidade com a API
const resp = await http.delete<unknown>(
`${ENDPOINTS.PATIENTS}/${encodeURIComponent(id)}`
`${ENDPOINTS.PATIENTS}?id=eq.${encodeURIComponent(id)}`
);
if (!resp.success) {
return {