Skip to content

Instantly share code, notes, and snippets.

@indreklasn
Last active December 6, 2019 12:24
Show Gist options
  • Save indreklasn/dc9fbfb7eaebf19efe2488d04553bdda to your computer and use it in GitHub Desktop.
Save indreklasn/dc9fbfb7eaebf19efe2488d04553bdda to your computer and use it in GitHub Desktop.
exports.handler = (event, context) => {
console.log('Lambda Function `products-read-all` invoked')
return client.query(q.Paginate(q.Match(q.Ref('indexes/all_products'))))
.then((response) => {
const productRefs = response.data
// create new query out of todo refs.
// https://docs.fauna.com/fauna/current/api/fql/
const getAllProductDataQuery = productRefs.map((ref) => {
return q.Get(ref)
})
// query the refs
return client.query(getAllProductDataQuery).then((ret) => {
return {
statusCode: 200,
body: JSON.stringify(ret)
}
})
}).catch((error) => {
console.log('error', error.message)
return {
statusCode: 400,
body: JSON.stringify(error.message)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment