fix(principal): integra auth, agenda e laudos com a api

This commit is contained in:
EdilbertoC
2026-04-28 10:22:54 -03:00
parent d576fb9784
commit 7199c107f2
20 changed files with 1121 additions and 331 deletions

View File

@@ -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() {