test_fauna_netlify/functions/todos-delete.js
2019-11-10 09:48:15 -06:00

28 lines
No EOL
866 B
JavaScript

/* code from functions/todos-update.js */
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 data = JSON.parse(event.body)
const id = getId(event.path)
console.log(`Function 'todo-update' invoked. update id: ${id}`)
return client.query(q.Update(q.Ref(`classes/todos/${id}`), { data }))
.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)
}
})
}