added functions

This commit is contained in:
WaylonWalker 2019-11-10 09:48:15 -06:00
parent 262502bff8
commit 2bae6e9269
6 changed files with 191 additions and 0 deletions

28
functions/todos-read.js Normal file
View file

@ -0,0 +1,28 @@
/* code from functions/todos-read.js */
/* Import faunaDB sdk */
const faunadb = require('faunadb')
const getId = require('./utils/getId')
const q = faunadb.query
const client = new faunadb.Client({
secret: process.env.FAUNADB_SERVER_SECRET
})
exports.handler = (event, context) => {
const id = getId(event.path)
console.log(`Function 'todo-read' invoked. Read id: ${id}`)
return client.query(q.Get(q.Ref(`classes/todos/${id}`)))
.then((response) => {
console.log('success', response)
return {
statusCode: 200,
body: JSON.stringify(response)
}
}).catch((error) => {
console.log('error', error)
return {
statusCode: 400,
body: JSON.stringify(error)
}
})
}