riseup-squad21/services/medicosApi.ts
2025-10-20 21:49:35 -03:00

41 lines
1.1 KiB
TypeScript

// Caminho: services/medicosApi.ts
import api from './api';
export interface Doctor {
id: any;
crm: string;
crm_uf: string;
[key: string]: any;
}
export const medicosApi = {
list: async (): Promise<Doctor[]> => {
const response = await api.get<Doctor[]>('/rest/v1/doctors?select=*');
return response.data;
},
getById: async (id: string): Promise<Doctor> => {
const response = await api.get<Doctor>(`/rest/v1/doctors?id=eq.${id}&select=*`, {
headers: { Accept: 'application/vnd.pgrst.object+json' },
});
return response.data;
},
create: async (data: Omit<Doctor, 'id'>): Promise<Doctor> => {
const response = await api.post<Doctor[]>('/rest/v1/doctors', data, {
headers: { 'Prefer': 'return=representation' }
});
return response.data[0];
},
update: async (id: string, data: Partial<Doctor>): Promise<Doctor> => {
const response = await api.patch<Doctor[]>(`/rest/v1/doctors?id=eq.${id}`, data, {
headers: { 'Prefer': 'return=representation' }
});
return response.data[0];
},
delete: async (id: string): Promise<void> => {
await api.delete(`/rest/v1/doctors?id=eq.${id}`);
},
};