Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Refactorizar de buscar a esperar que puede producir el mismo resultado

Así que moví un fragmento de código de solicitud de recuperación no reutilizable a mi API:

 let response = await fetch(visitURL, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + userJWT }, body: JSON.stringify(endingVisit) }); if (response.ok) { let {visitId, createdAt} = await response.json(); const viewVisitDto = new ViewVisitDto(`${visitId}${createdAt}${visitorId}${doctorId}${oldPatientId}`); return viewVisitDto; } else { throw new Error("deactivated!") }

Pude llegar tan lejos:

 axios.post(visitURL, { headers, body: JSON.stringify(visit) }).then((response) => { console.log(response); }).catch((error) => { console.log(error); })

Pero no me da exactamente el visitId y createdAt de la respuesta y no puedo usar una response.ok ni una response.json() . Esencialmente, necesito sacar ese visitId y createdAt que debería aparecer en la respuesta.

También intenté simplemente usar la biblioteca node-fetch , pero aunque en el código VS parece aceptarlo, TypeScript no está contento con él incluso cuando instalo @types/node-fetch e incluso cuando creo un archivo de definición de tipo para él, a mi API simplemente no le gusta.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Adivinando lo que buscas es

 // don't know axios, but if it returns a promise await it const dto = await axios.post(visitURL, { headers, body: JSON.stringify(visit) }).then((response) => { // parse response return {resonse.visitId, resonse.createdAt} }).then(({visitId, createdAt}) => { // form dto (where are other vals)? return new ViewVisitDto(`${visitId}${createdAt}${visitorId}${doctorId}${oldPatientId}`); }).catch((error) => { console.log(error); })

Sin embargo, no menciona de dónde provienen doctorId y oldPatientId ... Intenta proporcionar más información, incluida la salida de console.log y el código circundante

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!