Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning NaN when use sequelize.fn("count") #89

Open
Hoffmano opened this issue Jun 18, 2021 · 0 comments
Open

Returning NaN when use sequelize.fn("count") #89

Hoffmano opened this issue Jun 18, 2021 · 0 comments

Comments

@Hoffmano
Copy link

Hoffmano commented Jun 18, 2021

When I use Sequelize Mock between with a query like that:

const getStats = async () => {
  const {
    active,
    'in-progress': inProgress,
  } = await ImmediateCare.findAll({
    raw: true,
    attributes: ['status', [fn('count', col('id')), 'count']],
    group: ['ImmediateCare.status'],
  }).then((status) => {
    const counts = {
      active: 0,
      'in-progress': 0,
    }

    status.forEach((s) => {
      counts[s.status] = parseInt(s.count, 10)
    })

    return counts
  })

  const patientsPerProfessional = inProgress !== 0
    ? active / inProgress
    : active

  return {
    active,
    inProgress,
    patientsPerProfessional,
  }
}

Is being returned NaN, I'm guessing that is because Sequelize Mock can't mock sequelize.fn('count')
image

Is that right?

StackOverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant