Skip to content

Help #21

Description

@controlecn

Alguém pode me ajudar? Preciso puxar o ultimo cadastro do banco. assim ele me devolve o primeiro. Como faço para retornar o ultimo lançamento. Eu somo os valores de todas os lançamentos porém no campo (const atualiza = item.updatedAt) quero que pegue a data do ultimo lançamento feito, que seria apenas o ultimo registro.

'''js

getList = async () => { try { this.setState({ loading: true }); const { data } = await api.get(maquina/all/lancamentos/cards);

this.setList(data);
} catch (e) { console.log(e); } finally { this.setState({ loading: false }); } };

setList = data => {
let tempArr = []

for (let item of data) {
  if (!item.loja || !item.zona) continue

  const index = tempArr.findIndex(x => x.id === item.loja._id)

  if (index >= 0) {
    const entrada = (item.entrada_final - item.entrada_inicial) * item.jogo_valor
    const saida = (item.saida_final - item.saida_inicial) * item.jogo_valor

    tempArr[index].entrada += entrada
    tempArr[index].saida += saida
    tempArr[index].total += entrada - saida
  } else {
    const id = item.loja._id
    const entrada = (item.entrada_final - item.entrada_inicial) * item.jogo_valor
    const saida = (item.saida_final - item.saida_inicial) * item.jogo_valor
    const codigo = item.loja.codigo
    const descricao = item.loja.nome
    const total = entrada - saida
    const zona = item.zona.nome;
    const maquinas = this.state.maquinas.filter(x => x.zona._id === item.zona._id).length
    const atualiza = item.updatedAt

    tempArr.push({
      id,
      entrada,
      saida,
      codigo,
      descricao,
      total,
      maquinas,
      zona,
      atualiza

    })
  }
}


this.setState({ list: tempArr })

}

render() {
return (


    <Container>
      {this.state.loading && (
        <Row className="center">
          <MdRefresh className="icon-spin" size={100} />
        </Row>
      )}
      <Row>
        {this.state.list.map(item => (
          <Col md="4" key={item.id}>
            <div className="home-card" size={80}>
              <div className="home-flex">
                <FaStoreAlt size={60} />
                <div style={{ display: 'block' }}>
                <p><center><Label>{item.zona} -  {item.descricao}</Label></center></p>
                  <Label>Máquinas: {item.maquinas}</Label>
                  <Label>Faturamento: {toBrazilianCurrency(item.total)}</Label>
                  <center><td>Ultimo Lançamento: {this.formatDate(new Date(item.atualiza))}</td></center>
                </div>
              </div>
            </div>
          </Col>
        ))}
      </Row>
    </Container>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions