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