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

149
Views
Cómo mapear un resultado en una promesa que proviene de una llamada de función

Tengo esta función que devuelve un resultado de un GET en una API (estoy usando una API Rest de AWS, para la contextualización):

 const listUsers = async () => { const apiName = 'AdminQueries' const path = '/listUsers' const params = { headers: { 'Content-Type': 'application/json', Authorization: `${(await Auth.currentSession()) .getAccessToken() .getJwtToken()}`, }, } return await API.get(apiName, path, params) }

Y si llamo a la función para imprimir en la consola, como:

console.log(listUsers())

Obtengo una matriz en mi consola:

 Promise {<pending>} __proto__: Promise [[PromiseState]]: "fulfilled" [[PromiseResult]]: Object Users: Array(42) 0: {Username: "00e534e3-08ee-4bc1-9d19-ab18208e3f94", Attributes: Array(5), UserCreateDate: "2021-09-06T10:05:35.537Z", UserLastModifiedDate: "2021-09-06T10:05:35.537Z", Enabled: true, …} 1: {Username: "05f4ce2e-4b57-48d5-9f5f-e18d250aefb4", Attributes: Array(6), UserCreateDate: "2021-09-10T19:45:32.002Z", UserLastModifiedDate: "2021-09-10T19:54:37.333Z", Enabled: true, …} 2: {Username: "06a78cc7-af6a-4fb6-975d-458c089b69a5", Attributes: Array(6), UserCreateDate: "2021-09-10T18:04:27.780Z", UserLastModifiedDate: "2021-09-10T18:04:27.780Z", Enabled: true, …} 3: {Username: "32652d77-e7a4-444a-9995-f8f50eb14633", Attributes: Array(6), UserCreateDate: "2021-09-06T15:48:24.897Z", UserLastModifiedDate: "2021-09-06T15:49:39.476Z", Enabled: true, …} length: 42 __proto__: Array(0) __proto__: Object

¿Cómo mapeo a estos usuarios para mostrarlos en una matriz? Lo intenté pero no pude.

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

0

Su función listUsers está devolviendo una promesa. Para obtener la respuesta, puede hacer uso de algo como esto.

 const listUsers = async () => { const apiName = 'AdminQueries' const path = '/listUsers' const params = { headers: { 'Content-Type': 'application/json', Authorization: `${(await Auth.currentSession()) .getAccessToken() .getJwtToken()}`, }, } return await API.get(apiName, path, params) } **** update **** const func = async () => { const response = await listUsers(); console.log(response); } func();
about 4 years ago · Juan Pablo Isaza Report

0

const listUsers = async () => { const apiName = 'AdminQueries' const path = '/listUsers' const params = { headers: { 'Content-Type': 'application/json', Authorization: `${(await Auth.currentSession()) .getAccessToken() .getJwtToken()}`, }, } return await API.get(apiName, path, params) } const func = async () => { const response = await listUsers(); reponse.data?.map((item) => { console.log(item); }) }
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!