I have a value in my faunadb database that i want to increase by one when clicking a button.
I am not sure how to do that
i tried it with this:
const change = (data) => {
return fetch(`/.netlify/functions/todos-update`, {
body: JSON.stringify(data),
method: 'POST'
}).then(response => {
return response.json()
})
}
and triggered it with this
var dataa = document.getElementById('amount').innerHTML
change(("value: " + dataa))
my serverside code is this:
exports.handler = (event, context, callback) => {
const data = JSON.parse(event.body)
const id = "236323245287014920"
console.log(`Function 'todo-update' invoked. update id: ${id}`)
return client.query(q.Update(q.Ref(`classes/nappi/${id}`), {data}))
.then((response) => {
console.log('success', response)
return callback(null, {
statusCode: 200,
body: JSON.stringify(response)
})
}).catch((error) => {
console.log('error', error)
return callback(null, {
statusCode: 400,
body: JSON.stringify(error)
})
})
}
i expected this to increment my value in the database by 1 but in reality i get an error that looks like this: POST https://nappula.tk/.netlify/functions/todos-update 400 (Bad Request)
I am not sure where i went wrong