Last active
March 30, 2020 14:06
-
-
Save arnaudbesnier/ceb5d3b204f9274f9ec970e0987f6661 to your computer and use it in GitHub Desktop.
Forest Express - Admin API - Override on the associated records search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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