Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

286
Vistas
mecanografiado/nodo/secuencia: cómo agregar variables al obtener un valor dinámico

Obtengo todos los precios por consulta ( req.query.currency ) -

 // Gets currency column by query from crypto DB table const allPrices = await Crypto.findAll({ attributes: [req.query.currency, 'createdAt'], order: [['createdAt', 'ASC']] });

Los primeros 2 objetos en la matriz, por ejemplo:

 Crypto { dataValues: { ETHUSD: '4181.1015879408815', createdAt: 2021-10-21T08:16:37.000Z }, _previousDataValues: { ETHUSD: '4181.1015879408815', createdAt: 2021-10-21T08:16:37.000Z }, _changed: Set(0) {}, _options: { isNewRecord: false, _schema: null, _schemaDelimiter: '', raw: true, attributes: [ 'ETHUSD', 'createdAt' ] }, isNewRecord: false } Crypto { dataValues: { ETHUSD: '0', createdAt: 2021-10-21T08:17:16.000Z }, _previousDataValues: { ETHUSD: '0', createdAt: 2021-10-21T08:17:16.000Z }, _changed: Set(0) {}, _options: { isNewRecord: false, _schema: null, _schemaDelimiter: '', raw: true, attributes: [ 'ETHUSD', 'createdAt' ] }, isNewRecord: false }

Tengo 3 opciones en req.query.currency - BTCUSD, ETHUSD, LTCUSD.

Obtendré uno de ellos cuando envíe la solicitud, cada uno representa la diferencia entre el primer valor, luego necesito agregarles el primer valor de esta manera:

 const toClient = allPrices.map((item, index) => { if (index === 0) { return item; } return { ...item, price: (+allPrices[0] + +item).toString(), } });

Los primeros 2 objetos en la matriz -

 Crypto { dataValues: { ETHUSD: '4181.1015879408815', createdAt: 2021-10-21T08:16:37.000Z }, _previousDataValues: { ETHUSD: '4181.1015879408815', createdAt: 2021-10-21T08:16:37.000Z }, _changed: Set(0) {}, _options: { isNewRecord: false, _schema: null, _schemaDelimiter: '', raw: true, attributes: [ 'ETHUSD', 'createdAt' ] }, isNewRecord: false } { dataValues: { ETHUSD: '0', createdAt: 2021-10-21T08:17:16.000Z }, _previousDataValues: { ETHUSD: '0', createdAt: 2021-10-21T08:17:16.000Z }, _changed: Set(0) {}, _options: { isNewRecord: false, _schema: null, _schemaDelimiter: '', raw: true, attributes: [ 'ETHUSD', 'createdAt' ] }, isNewRecord: false, price: 'NaN' }

¿Cómo puedo obtener un valor en el price: 'NaN' ?

No puedo hacerlo así -

 return { ...item, price: (+allPrices[0].BTCUSD + +item.BTCUSD).toString(), }

Porque no sé cuál será la moneda. Así que necesito una forma de poner el req.query.currency aquí - (+allPrices[0]. BTCUSD + +item. BTCUSD ) ¿Cómo puedo hacer eso?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda