Created
October 21, 2018 10:16
-
-
Save lokhmakov/87e174f378471294cffb1ff4a0319ba4 to your computer and use it in GitHub Desktop.
routes/index.js
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 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