excluir paciente funcional
This commit is contained in:
parent
e5f55c1f69
commit
fc6acff393
@ -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");
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user