Query is not defined

## Feature(s) impacted
Smart charts, sql queries, multiple line charts

## Observed behavior
I figured out how to implement a new route for an API time based chart with the documentation but the request is obliged to be a POST ? Why not a GET ?

See here below my code :

The query functions as I tested it before in a query chart, but I get only one line.
## Expected behavior
I want to have a superposition of the users in a time chart. In order to make my dashboard more efficient.

## Failure Logs
This is what I get from the console :slight_smile:

Have you any idea why I get this error ?

## Context

  • Project name: ExplorJob
  • Team name: Interface developpers
  • Database type: postgre sql

Thanks for your help !

Hello @Nils_Guicherd,

I figured out how to implement a new route for an API time based chart with the documentation but the request is obliged to be a POST ? Why not a GET ?

Indeed the only method we support is a POST for API charts, this was done to allow users retrieving data from the payload body in a way that is secure and follow conventions.

For your error without looking too much at the code you’ve written, it is simply caused by the fact that sequelize is not defined when calling models.sequelize.query().

You should be able to find the right path/object that exports sequelize in models/index.js

Best regards,

Sorry, but I do not understand your answer. What do I have to do to define models.sequelize.

I do not have any new API based chart for me to look for. I read theses documentation1 & documentation2 and tried to combine the two.

My code is likely the same as doc 1.

I also thought about writing a smart chart via builder and try to use liana…fetch() :

    async fetchData() {
      const response = await this.lianaServerFetch.fetch('/forest/multiline/users/months', { });
      const result = await response.json();
      this.users = result.data.map(user => {
        const convertedUser =  user;
        return convertedUser;

Is that a possibility ?

I also asked in a previous post : post smart chart my problems.

You can define a smart chart to handle multiple lines at once since it cannot be done with the components out of the box in FA. But you will still face the issue that models.sequelize is not defined.

As shown in the documentation links you have shared, models is imported from models/index.js at the root of your agent’s code. Your sequelize instance should be defined and exported from that file.

I could help you more if you are willing to share the content of the models/index.js file but if not you can look at an example project I have made a while back here. It uses multiple connections support and you can see here how I fetch the sequelize instance to execute a query.

It is from the beginning imported from ../models

And my file models/index.js is exactly the same as yours : https://github.com/DayTF/smart-relationship/blob/main/models/index.js

if the file contents are the same in models/index.js.
You should be able to execute your query the same way I did: models.connections.default.query()

Thanks ! After multiple tries I managed to get what I wanted :slight_smile:

Thanks to this snippet of code :

 /* Get the Y-axis values */
      var usersProsKeys = _.uniq(records.map((r) => r.userspros));
      var usersExplosKeys = _.uniq(records.map((r) => r.usersexplos));

      /* Build one array per key / line */
        key: 'usersExlos',
        values: usersExplosKeys
        key: 'usersPros',
        values: usersProsKeys