excluir paciente funcional
This commit is contained in:
parent
e5f55c1f69
commit
fc6acff393
@ -613,9 +613,14 @@ const PainelSecretaria = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await deletePatient(paciente.id);
|
const resp = await deletePatient(paciente.id);
|
||||||
|
if (resp && resp.success) {
|
||||||
setPacientes((prev) => prev.filter((p) => p.id !== paciente.id));
|
setPacientes((prev) => prev.filter((p) => p.id !== paciente.id));
|
||||||
toast.success("Paciente removido");
|
toast.success("Paciente removido");
|
||||||
|
} else {
|
||||||
|
console.error("Falha ao remover paciente (API):", resp?.error);
|
||||||
|
toast.error(resp?.error || "Erro ao remover paciente");
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erro ao remover paciente:", error);
|
console.error("Erro ao remover paciente:", error);
|
||||||
toast.error("Erro ao remover paciente");
|
toast.error("Erro ao remover paciente");
|
||||||
|
|||||||
@ -535,8 +535,10 @@ export async function updatePatient(
|
|||||||
export async function deletePatient(id: string): Promise<ApiResponse<void>> {
|
export async function deletePatient(id: string): Promise<ApiResponse<void>> {
|
||||||
if (!id) return { success: false, error: "ID é obrigatório" };
|
if (!id) return { success: false, error: "ID é obrigatório" };
|
||||||
try {
|
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>(
|
const resp = await http.delete<unknown>(
|
||||||
`${ENDPOINTS.PATIENTS}/${encodeURIComponent(id)}`
|
`${ENDPOINTS.PATIENTS}?id=eq.${encodeURIComponent(id)}`
|
||||||
);
|
);
|
||||||
if (!resp.success) {
|
if (!resp.success) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user