How to use forest-express-sequelize - 10 common examples

To help you get started, we’ve selected a few forest-express-sequelize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github doug2k1 / my-money / src / index.js View on Github external
// view engine
app.set('view engine', 'ejs');
app.set('views', './src/views');

// session
app.use(
  session({
    secret: process.env.SESSION_KEY,
    resave: false,
    saveUninitialized: false
  })
);

// Forest Admin
app.use(
  ForestAdmin.init({
    modelsDir: path.resolve('./src/models'),
    envSecret: process.env.FOREST_ENV_SECRET,
    authSecret: process.env.FOREST_AUTH_SECRET,
    sequelize
  })
);

// auth
setupAuth(app);

// graphql
setupGraphQL(app);

// static files
app.use(express.static('public'));
github opencollective / opencollective-api / server / lib / forest.js View on Github external
export default app => {
  if (!process.env.FOREST_ENV_SECRET || !process.env.FOREST_AUTH_SECRET) {
    return;
  }

  app.use(init());

  app.post('/forest/actions/activate-subscription', Liana.ensureAuthenticated, (req, res) => {
    const data = req.body.data;
    const id = data.attributes.ids[0];
    models.Subscription.findOne({ where: { id } })
      .then(subscription => subscription.activate())
      .then(() => {
        res.status(200).send({ success: 'The subscription was successfully activated.' });
      })
      .catch(e => {
        res.status(400).send({ error: e.message });
      });
  });

  app.post('/forest/actions/cancel-subscription', Liana.ensureAuthenticated, (req, res) => {
    const data = req.body.data;
    const id = data.attributes.ids[0];
    models.Subscription.findOne({ where: { id } })
github opencollective / opencollective-api / server / lib / forest.js View on Github external
const msg = 'The user and its dependencies were successfully deleted.';
      res.status(200).send({
        html: `<p>${msg}</p>
               <p><a href="../../../">Click here to continue</a>.</p>`,
      });
    } catch (e) {
      const msg = e.message;
      res.status(400).send({
        error: `There was an error while processing your request.\n
          "${msg}"\n
          Maybe you want to proceed manually?`,
      });
    }
  });

  app.post('/forest/actions/delete-user-and-merge', Liana.ensureAuthenticated, async (req, res) =&gt; {
    const data = req.body.data;
    console.log(data);
    const id = data.attributes.ids[0];
    const mergeIntoUserId = data.attributes.values['User ID'];
    try {
      const user = await models.User.findOne({ where: { id } });
      const userCollective = await models.Collective.findOne({
        where: { id: user.CollectiveId },
      });
      if (!user || !userCollective) {
        throw Error('Can not fetch origin user.');
      }
      const mergeIntoUser = await models.User.findOne({
        where: { id: mergeIntoUserId },
      });
      const mergeIntoUserCollective = await models.Collective.findOne({
github ForestAdmin / forest-live-demo-lumber / app.js View on Github external
credentialsRequired: false
}));

fs.readdirSync('./decorators/routes').forEach((file) => {
  if (file[0] !== '.') {
    app.use('/forest', require(`./decorators/routes/${file}`));
  }
});

fs.readdirSync('./routes').forEach((file) => {
  if (file[0] !== '.') {
    app.use('/forest', require('./routes/' + file));
  }
});

app.use(require('forest-express-sequelize').init({
  modelsDir: __dirname + '/models',
  envSecret: process.env.FOREST_ENV_SECRET,
  authSecret: process.env.FOREST_AUTH_SECRET,
  sequelize: require('./models').sequelize,
  integrations: {
    stripe: {
      apiKey: process.env.STRIPE_SECRET_KEY,
      mapping: 'customers.stripe_id',
      stripe: require('stripe')
    }
  }
}));

module.exports = app;
github opencollective / opencollective-api / server / lib / forest.js View on Github external
export const init = () =>
  Liana.init({
    modelsDir: path.resolve(__dirname, '../models'),
    configDir: path.resolve(__dirname, '../forest'),
    envSecret: process.env.FOREST_ENV_SECRET,
    authSecret: process.env.FOREST_AUTH_SECRET,
    connections: [{ models: getForestModels(), options: sequelize.options }],
    sequelize: sequelize.Sequelize,
  });
github ForestAdmin / graphql-stitcher / example / movies / Movies / graphql / actor_images.js View on Github external
count_actor_images: async (obj, params) => {
          if (!params.filterType) { params.filterType = 'and'; }
          if (!params.timezone) { params.timezone = 'Europe/London'; }

          return await new Liana.ResourcesGetter(models.actor_images, opts, params).count();
        },
        list_actor_images: async (obj, params) => {
github ForestAdmin / graphql-stitcher / example / movies / Movies / graphql / schema_migrations.js View on Github external
count_schema_migrations: async (obj, params) => {
          if (!params.filterType) { params.filterType = 'and'; }
          if (!params.timezone) { params.timezone = 'Europe/London'; }

          return await new Liana.ResourcesGetter(models.schema_migrations, opts, params).count();
        },
        list_schema_migrations: async (obj, params) => {
github ForestAdmin / graphql-stitcher / example / meals / Meals / graphql / chef_availabilities.js View on Github external
list_chef_availabilities: async (obj, params) => {
          if (!params.filterType) { params.filterType = 'and'; }
          if (!params.timezone) { params.timezone = 'Europe/London'; }

          const r = await new Liana.ResourcesGetter(models.chef_availabilities, opts, params).perform();
          return r[0];
        },
        get_chef_availabilities: async (obj, { id }, context, info) => {
github ForestAdmin / graphql-stitcher / example / movies / Movies / graphql / genres.js View on Github external
count_genres: async (obj, params) => {
          if (!params.filterType) { params.filterType = 'and'; }
          if (!params.timezone) { params.timezone = 'Europe/London'; }

          return await new Liana.ResourcesGetter(models.genres, opts, params).count();
        },
        list_genres: async (obj, params) => {
github ForestAdmin / graphql-stitcher / example / movies / Movies / graphql / genres_movies.js View on Github external
list_genres_movies: async (obj, params) => {
          if (!params.filterType) { params.filterType = 'and'; }
          if (!params.timezone) { params.timezone = 'Europe/London'; }

          const r = await new Liana.ResourcesGetter(models.genres_movies, opts, params).perform();
          return r[0];
        },
        get_genres_movies: async (obj, { id }, context, info) => {