Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arnaudbesnier/ceb5d3b204f9274f9ec970e0987f6661 to your computer and use it in GitHub Desktop.
Save arnaudbesnier/ceb5d3b204f9274f9ec970e0987f6661 to your computer and use it in GitHub Desktop.
Forest Express - Admin API - Override on the associated records search
const Liana = require('forest-express-sequelize');
const models = require('./models');
// NOTICE: "collection" has to be replaced by the collection/model you want to customize.
app.get('/forest/collection', (request, response, next) => {
if (!request.query.searchToEdit) {
// NOTICE: Seach for collection list, keep the current behaviour.
return next();
}
// NOTICE: Seach for association update, override the behaviour the way you want.
return models.collection
.findAll({ limit: 3 })
.then(collections =>
new Liana.ResourceSerializer(
Liana,
models.collection,
collections,
{},
{ count: 3 }
).perform())
.then(collections => response.send(collections))
.catch(next);
});
Liana.init({
// ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment