fix(principal): integra auth, agenda e laudos com a api
This commit is contained in:
@@ -1,8 +1,50 @@
|
||||
import { appointments as mockAppointments } from '../data/mockData.js'
|
||||
import { apiConfig, apiEndpoint, getAuthenticatedHeaders } from '../config/api.js'
|
||||
import { appointmentMapper } from '../mappers/appointmentMapper.js'
|
||||
import { fetchJsonWithFallback, normalizeCollection, normalizeItem } from './repositoryUtils.js'
|
||||
|
||||
export const appointmentRepository = {
|
||||
getAll() {
|
||||
return mockAppointments
|
||||
async getAll() {
|
||||
const data = await fetchJsonWithFallback(
|
||||
[
|
||||
{
|
||||
url: apiEndpoint('/agendamentos'),
|
||||
options: { headers: getAuthenticatedHeaders() },
|
||||
},
|
||||
{
|
||||
url: `${apiConfig.restUrl}/appointments?select=*,patients(full_name),doctors(name)`,
|
||||
options: { headers: getAuthenticatedHeaders() },
|
||||
},
|
||||
],
|
||||
'Erro ao buscar agendamentos.',
|
||||
)
|
||||
|
||||
return normalizeCollection(data, ['agendamentos', 'appointments', 'data']).map(appointmentMapper.toUi)
|
||||
},
|
||||
|
||||
async create(uiData) {
|
||||
const data = await fetchJsonWithFallback(
|
||||
[
|
||||
{
|
||||
url: apiEndpoint('/agendamentos'),
|
||||
options: {
|
||||
method: 'POST',
|
||||
headers: getAuthenticatedHeaders(),
|
||||
body: JSON.stringify(appointmentMapper.toApi(uiData)),
|
||||
},
|
||||
},
|
||||
{
|
||||
url: `${apiConfig.restUrl}/appointments`,
|
||||
options: {
|
||||
method: 'POST',
|
||||
headers: getAuthenticatedHeaders({ Prefer: 'return=representation' }),
|
||||
body: JSON.stringify(appointmentMapper.toApi(uiData, 'supabase')),
|
||||
},
|
||||
},
|
||||
],
|
||||
'Falha ao criar o agendamento.',
|
||||
)
|
||||
|
||||
return appointmentMapper.toUi(normalizeItem(data, ['agendamento', 'appointment', 'data']))
|
||||
},
|
||||
|
||||
getTodayTimeline() {
|
||||
|
||||
Reference in New Issue
Block a user