fix: Implementar sintaxe PostgREST para update/delete em patientService e doctorService

This commit is contained in:
guisilvagomes 2025-10-23 16:54:04 -03:00
parent b85a43dd3e
commit e163a1dc7e
2 changed files with 12 additions and 6 deletions

View File

@ -79,8 +79,11 @@ class DoctorService {
*/ */
async update(id: string, data: UpdateDoctorInput): Promise<Doctor> { async update(id: string, data: UpdateDoctorInput): Promise<Doctor> {
try { try {
const response = await apiClient.patch<Doctor>(`/doctors/${id}`, data); const response = await apiClient.patch<Doctor[]>(`/doctors?id=eq.${id}`, data);
return response.data; if (response.data && response.data.length > 0) {
return response.data[0];
}
throw new Error("Médico não encontrado");
} catch (error) { } catch (error) {
console.error("Erro ao atualizar médico:", error); console.error("Erro ao atualizar médico:", error);
throw error; throw error;
@ -92,7 +95,7 @@ class DoctorService {
*/ */
async delete(id: string): Promise<void> { async delete(id: string): Promise<void> {
try { try {
await apiClient.delete(`/doctors/${id}`); await apiClient.delete(`/doctors?id=eq.${id}`);
} catch (error) { } catch (error) {
console.error("Erro ao deletar médico:", error); console.error("Erro ao deletar médico:", error);
throw error; throw error;

View File

@ -78,8 +78,11 @@ class PatientService {
*/ */
async update(id: string, data: UpdatePatientInput): Promise<Patient> { async update(id: string, data: UpdatePatientInput): Promise<Patient> {
try { try {
const response = await apiClient.patch<Patient>(`/patients/${id}`, data); const response = await apiClient.patch<Patient[]>(`/patients?id=eq.${id}`, data);
return response.data; if (response.data && response.data.length > 0) {
return response.data[0];
}
throw new Error("Paciente não encontrado");
} catch (error) { } catch (error) {
console.error("Erro ao atualizar paciente:", error); console.error("Erro ao atualizar paciente:", error);
throw error; throw error;
@ -91,7 +94,7 @@ class PatientService {
*/ */
async delete(id: string): Promise<void> { async delete(id: string): Promise<void> {
try { try {
await apiClient.delete(`/patients/${id}`); await apiClient.delete(`/patients?id=eq.${id}`);
} catch (error) { } catch (error) {
console.error("Erro ao deletar paciente:", error); console.error("Erro ao deletar paciente:", error);
throw error; throw error;