Create 'Smart Action' on preExisting NodeJs / Sequelize app

Expected behavior

After creating a /forest/form_templates.js file with the following code:

const { collection } = require("forest-express-sequelize");

collection("form_templates", {
  actions: [
    {
      name: "Mark as Live",
    },
  ],
});

And adding the following to my app initialization code:

  const forest = require("forest-express-sequelize");
  // .....
  app.use(
    await forest.init({
      envSecret: process.env.FOREST_ENV_SECRET,
      authSecret: process.env.FOREST_AUTH_SECRET,
      objectMapping: objectMapping,
      connections: { default: sequelize },
      configDir: path.join(__dirname, "./forest"), <<<<<< HERE: points to /forest dir
    })
  );

I expect to see a Smart Action show up in my admin panel:

Actual behavior

The ‘Mark as Live’ Smart Action does not show up:

Context

the model lives in a form_template.js file
the model name is: FormTemplate
the corresponding pgsql table name is: form_templates

“express”: “^4.17.1”,
“forest-express-sequelize”: “^7.12.0”,
“sequelize”: “^6.6.2”

Is it a naming issue or am I not using the forest.init() function properly ?

Thanks,
Camille

Turns out in the collection declaration, you need to pass the model name
so if the model is called FormTemplate, your must pass a “FormTemplate” string to the collection function.

collection("FormTemplate", {
  actions: [
    {
      name: "Mark as Live",
    },
  ],
});
1 Like