Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

282
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda