forked from RiseUP/riseup-squad21
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
// Caminho: services/agendamentosApi.ts
|
|
import api from './api';
|
|
|
|
export interface Appointment {
|
|
id: any;
|
|
patient_id: string;
|
|
doctor_id: string;
|
|
scheduled_at: string;
|
|
[key: string]: any;
|
|
}
|
|
|
|
interface AvailableSlotsData {
|
|
doctor_id: string;
|
|
start_date: string;
|
|
end_date: string;
|
|
appointment_type?: 'presencial' | 'telemedicina';
|
|
}
|
|
|
|
export const agendamentosApi = {
|
|
list: async (): Promise<Appointment[]> => {
|
|
const response = await api.get<Appointment[]>('/rest/v1/appointments?select=*');
|
|
return response.data;
|
|
},
|
|
|
|
getById: async (id: string): Promise<Appointment> => {
|
|
const response = await api.get<Appointment>(`/rest/v1/appointments?id=eq.${id}&select=*`, {
|
|
headers: { Accept: 'application/vnd.pgrst.object+json' },
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
create: async (data: Omit<Appointment, 'id'>): Promise<Appointment> => {
|
|
const response = await api.post<Appointment[]>('/rest/v1/appointments', data, {
|
|
headers: { 'Prefer': 'return=representation' }
|
|
});
|
|
return response.data[0];
|
|
},
|
|
|
|
update: async (id: string, data: Partial<Appointment>): Promise<Appointment> => {
|
|
const response = await api.patch<Appointment[]>(`/rest/v1/appointments?id=eq.${id}`, data, {
|
|
headers: { 'Prefer': 'return=representation' }
|
|
});
|
|
return response.data[0];
|
|
},
|
|
|
|
delete: async (id: string): Promise<void> => {
|
|
await api.delete(`/rest/v1/appointments?id=eq.${id}`);
|
|
},
|
|
|
|
searchAvailableSlots: async (data: AvailableSlotsData): Promise<any> => {
|
|
const response = await api.post('/functions/v1/get-available-slots', data);
|
|
return response.data;
|
|
},
|
|
}; |