Estaba trabajando en Angular, queria acceder a un objeto pero me dice que viene indefinido, cuando obtengo la respuesta e incluso use el operador '?' para evitar errores no entiendo que esta pasando
Mire este es el get en mi servicio
getRoomInfo(params: string){
return this.http.get<Room>(environment.api_URL + `appointments/${params}/getInfo-room`);
}
Como ven le paso el tipado de este, ajá y este es el objeto en donde quiero obtener la res de la peticion. Este es la interfaz que hice (quicktipe):
export interface Room {
infoRoom: InfoRoom
}
export interface InfoRoom {
_id: string;
medicalAppointment: MedicalAppointment;
affiliate: Affiliate;
channelId: string;
roomId: string;
appId: string;
customer: Customer;
time: Date;
createdAt: Date;
updatedAt: Date;
__v: number;
}
export interface Affiliate {
insurances: any[];
officePhone: string[];
enabled: boolean;
active: boolean;
approved: boolean;
degree: Degree[];
certificateCollege: any[];
currency: string;
timezone: string;
isTopDokto: boolean;
appointmentsFromApp: boolean;
rating: number;
feedbackCount: number;
maxOverbooking: number;
commission: number;
_id: string;
firstName: string;
lastName: string;
fullName: string;
email: string;
name: string;
vid: number;
affiliateType: string;
country: string;
attachments: any[];
createdAt: Date;
updatedAt: Date;
__v: number;
address: string;
cellPhone: string;
gender: string;
identification: string;
rtn: string;
specialty: string;
yearsExperience: number;
etag: string;
image: string;
previewLink: string;
socialDescription: string;
socialTitle: string;
urlShort: string;
userName: string;
otherEspecialty: string;
id: string;
}
export interface Degree {
fieldname: string;
originalname: string;
encoding: string;
mimetype: string;
size: string;
filename: string;
uuid: string;
name: string;
bucket: string;
}
export interface Customer {
cellPhone: any[];
officePhone: any[];
email: string[];
allergies: any[];
diseases: any[];
badHabits: any[];
enabled: boolean;
active: boolean;
completedProfile: boolean;
accountVerify: boolean;
verifiedCellphone: boolean;
verifiedEmail: boolean;
_id: string;
firstName: string;
lastName: string;
username: string;
fullName: string;
userType: string;
country: string;
createdAt: Date;
updatedAt: Date;
__v: number;
birthDate: Date;
countryDetails: CountryDetails;
}
export interface CountryDetails {
callingCodes: string[];
_id: string;
name: string;
topLevelDomain: string[];
alpha2Code: string;
alpha3Code: string;
capital: string;
altSpellings: string[];
region: string;
subregion: string;
population: number;
latlng: number[];
demonym: string;
area: number;
gini: number;
timezones: string[];
borders: string[];
nativeName: string;
numericCode: string;
currencies: Currency[];
languages: Language[];
translations: Translations;
flag: string;
regionalBlocs: RegionalBloc[];
cioc: string;
code: number;
}
export interface Currency {
code: string;
name: string;
symbol: string;
}
export interface Language {
iso639_1: string;
iso639_2: string;
name: string;
nativeName: string;
}
export interface RegionalBloc {
acronym: string;
name: string;
otherAcronyms: string[];
otherNames: string[];
}
export interface Translations {
de: string;
es: string;
fr: string;
ja: string;
it: string;
br: string;
pt: string;
nl: string;
hr: string;
fa: string;
}
export interface MedicalAppointment {
status: string;
purpose: string;
contactEmail: string[];
contactPhone: any[];
service: string[];
paymentStatus: string;
enabled: boolean;
chargeFee: boolean;
reserveSlots: boolean;
_id: string;
draft: boolean;
pendingAction: string;
place: string;
affiliate: string;
patient: string;
items: Item[];
appointmentSource: string;
start: Date;
end: Date;
symptom: string;
date: Date;
createdAt: Date;
updatedAt: Date;
__v: number;
}
export interface Item {
quantity: number;
price: number;
tax: number;
_id: string;
category: string;
service: string;
}
Este es el json:
{
"videoCallRoom": {
"_id": "62a79271fa19bd3e1cf594c7",
"medicalAppointment": {
"status": "scheduled",
"purpose": "consultation",
"contactEmail": [
""
],
"contactPhone": [],
"service": [
"5f88fc33596ccdbcee46fea9"
],
"paymentStatus": "paid",
"enabled": true,
"chargeFee": true,
"reserveSlots": true,
"_id": "62a79271fa19bd3e1cf594c5",
"draft": false,
"pendingAction": "affiliate",
"place": "5f88fc33596ccd81ce46fea5",
"affiliate": "5f88fad8fbe0751540193757",
"patient": "60f70f6a913cf44447b1605b",
"items": [
{
"quantity": 1,
"price": 500,
"tax": 0,
"_id": "5f88fc33596ccdbcee46fea9",
"category": "5ebaeb1f8a63e8294a2f0b4e",
"service": "5ebae8f65d8a9e7bab97f59c"
}
],
"appointmentSource": "",
"start": "2022-07-01T03:00:00.000Z",
"end": "2022-07-01T04:00:00.000Z",
"symptom": "",
"date": "2022-07-01T03:00:00.000Z",
"createdAt": "2022-06-13T19:39:29.319Z",
"updatedAt": "2022-06-13T19:39:29.319Z",
"__v": 0
},
"affiliate": {
"insurances": [],
"officePhone": [
"+"
],
"enabled": true,
"active": true,
"approved": true,
"degree": [
{
"fieldname": "file",
"originalname": "undefined/afd55c09-5976-4f2a-9549-6b1fa25d5a9d-Affiliate-degree-geo-app.postman-collection.json",
"encoding": "7bit",
"mimetype": "application/json",
"size": "2884",
"filename": "degree",
"uuid": "afd55c09-5976-4f2a-9549-6b1fa25d5a9d",
"name": "",
"bucket": "-documents"
}
],
"certificateCollege": [],
"currency": "HNL",
"timezone": "America/Tegucigalpa",
"isTopDokto": false,
"appointmentsFromApp": true,
"rating": 4,
"feedbackCount": 0,
"maxOverbooking": 0,
"commission": 16,
"_id": "5f88fad8fbe0751540193757",
"firstName": "Juan",
"lastName": "Perez",
"fullName": "Juan Perez",
"email": "",
"name": "La Cafe",
"vid": 151251,
"affiliateType": "5d242fc13555ec2b76e86bcd",
"country": "HND",
"attachments": [],
"createdAt": "2020-10-16T01:43:52.183Z",
"updatedAt": "2022-06-09T17:35:10.134Z",
"__v": 0,
"address": "Jardines del Valle",
"cellPhone": "99928583",
"gender": "M",
"identification": "0501199011757",
"rtn": "05011990117573",
"specialty": "Medicina General y Cirugia",
"yearsExperience": 10,
"etag": "\"f458b9417e2a60b472edc82a7a15d59c\"",
"image": "h",
"previewLink": "",
"socialDescription": "Agenda tu cita con el Doctor Agenda tu cita con el DoctorAgenda tu cita con el DoctorAgenda tu cita con el tu cita con el t",
"socialTitle": "Juan Perez",
"urlShort": "",
"userName": "juanperez1",
"otherEspecialty": "Cirugia",
"id": "5f88fad8fbe0751540193757"
},
"channelId": "62a79271fa19bd3e1cf594c5",
"roomId": "62a79271fa19bd3e1cf594c5",
"appId": "453bee4ca9fa4648bbe374f5237fc810",
"customer": {
"cellPhone": [],
"officePhone": [],
"email": [
""
],
"allergies": [],
"diseases": [],
"badHabits": [],
"enabled": true,
"active": true,
"completedProfile": false,
"accountVerify": false,
"verifiedCellphone": false,
"verifiedEmail": false,
"_id": "60f70f6a913cf44447b1605b",
"firstName": "",
"lastName": "Dev",
"username": "",
"fullName": "",
"userType": "5cd51ff333d554e479daaee9",
"country": "HND",
"createdAt": "2021-07-20T18:01:14.975Z",
"updatedAt": "2021-07-20T20:09:23.923Z",
"__v": 0,
"birthDate": "1998-04-23T06:53:16.000Z",
"countryDetails": {
"callingCodes": [
"504"
],
"_id": "5a63e334e05e270777521a16",
"name": "Honduras",
"topLevelDomain": [
".hn"
],
"alpha2Code": "HN",
"alpha3Code": "HND",
"capital": "Tegucigalpa",
"altSpellings": [
"HN",
"Republic of Honduras",
"República de Honduras"
],
"region": "Americas",
"subregion": "Central America",
"population": 8576532,
"latlng": [
15,
-86.5
],
"demonym": "Honduran",
"area": 112492,
"gini": 57,
"timezones": [
"UTC-06:00"
],
"borders": [
"GTM",
"SLV",
"NIC"
],
"nativeName": "Honduras",
"numericCode": "340",
"currencies": [
{
"code": "HNL",
"name": "Honduran lempira",
"symbol": "L"
}
],
"languages": [
{
"iso639_1": "es",
"iso639_2": "spa",
"name": "Spanish",
"nativeName": "Español"
}
],
"translations": {
"de": "Honduras",
"es": "Honduras",
"fr": "Honduras",
"ja": "ホンジュラス",
"it": "Honduras",
"br": "Honduras",
"pt": "Honduras",
"nl": "Honduras",
"hr": "Honduras",
"fa": "هندوراس"
},
"flag": "https://restcountries.eu/data/hnd.svg",
"regionalBlocs": [
{
"acronym": "CAIS",
"name": "Central American Integration System",
"otherAcronyms": [
"SICA"
],
"otherNames": [
"Sistema de la Integración Centroamericana,"
]
}
],
"cioc": "HON",
"code": 504
}
},
"time": "2022-07-01T04:00:00.000Z",
"createdAt": "2022-06-13T19:39:29.411Z",
"updatedAt": "2022-06-13T19:39:29.411Z",
"__v": 0
}
}
En react esto ya me habia pasado que no podia acceder a un atributo por mas que si existia, asi que hice uso de las operaciones ternarias algo asi: res ? res.data : null
Pero es que de ninguna de las dos formas me funciona y ya no se que otra forma pudiera hacerlo, tal vez que no estoy tratando la data como deberia
videoCallRoom
y la de la interfaz esinfoRoom
. Revisa eso porque los nombres deben ser iguales.