fix(principal): integra auth, agenda e laudos com a api
This commit is contained in:
@@ -1,8 +1,23 @@
|
||||
import { professionals as mockProfessionals } from '../data/mockData.js'
|
||||
import { apiConfig, apiEndpoint, getAuthenticatedHeaders } from '../config/api.js'
|
||||
import { fetchJsonWithFallback, normalizeCollection } from './repositoryUtils.js'
|
||||
|
||||
export const professionalRepository = {
|
||||
getAll() {
|
||||
return mockProfessionals
|
||||
async getAll() {
|
||||
const data = await fetchJsonWithFallback(
|
||||
[
|
||||
{
|
||||
url: apiEndpoint('/listar-medicos'),
|
||||
options: { headers: getAuthenticatedHeaders() },
|
||||
},
|
||||
{
|
||||
url: `${apiConfig.restUrl}/doctors`,
|
||||
options: { headers: getAuthenticatedHeaders() },
|
||||
},
|
||||
],
|
||||
'Erro ao buscar medicos.',
|
||||
)
|
||||
|
||||
return normalizeCollection(data, ['medicos', 'doctors', 'professionals', 'data']).map(mapProfessional)
|
||||
},
|
||||
|
||||
getCoverageMap() {
|
||||
@@ -12,3 +27,15 @@ export const professionalRepository = {
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
function mapProfessional(doctor) {
|
||||
return {
|
||||
id: String(doctor.id || doctor.medico_id || doctor.user_id || doctor.name || doctor.nome),
|
||||
name: doctor.name || doctor.nome || doctor.full_name || 'Medico(a)',
|
||||
role: doctor.specialty || doctor.speciality || doctor.especialidade || doctor.role || 'Medico(a)',
|
||||
schedule: doctor.schedule || doctor.agenda || doctor.disponibilidade || 'Seg a Sex, 08h as 18h',
|
||||
nextSlot: doctor.nextSlot || doctor.proximo_horario || doctor.next_slot || 'Consulta pendente',
|
||||
patients: doctor.patients || doctor.pacientes_ativos || doctor.active_patients || 0,
|
||||
status: doctor.status || doctor.situacao || 'Disponivel',
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user