Skip to content

Instantly share code, notes, and snippets.

@lokhmakov
Created October 21, 2018 10:16
Show Gist options
  • Save lokhmakov/87e174f378471294cffb1ff4a0319ba4 to your computer and use it in GitHub Desktop.
Save lokhmakov/87e174f378471294cffb1ff4a0319ba4 to your computer and use it in GitHub Desktop.
routes/index.js
...
const populateRelated = (model, fieldList) => new Promise((resolve) => {
keystone.populateRelated(model, fieldList, () => {
resolve(model)
})
})
...
keystoneApp.get('/api/core/entity', async (req, res, next) => {
try {
const CoreEntity = keystone.list('CoreEntity')
const result = await populateRelated(
await CoreEntity.model.find().exec(),
['fields']
).map((doc) => {
const fields = doc.fields.map((fieldDoc) => fieldDoc.toJSON())
return {
...doc.toJSON(),
fields,
}
})
res.json(result)
} catch (err) {
if (err) throw err
}
})
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment