Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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'));
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 } })
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) => {
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({
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;
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,
});
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) => {
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) => {
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) => {
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) => {
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) => {