update env key to FAUNADB_SERVER_SECRET
This commit is contained in:
parent
9b089e7c04
commit
271721bbc0
11 changed files with 18396 additions and 111 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import faunadb from 'faunadb'
|
||||
import getId from './utils/getId'
|
||||
|
||||
const q = faunadb.query
|
||||
const client = new faunadb.Client({
|
||||
|
|
@ -9,24 +8,24 @@ const client = new faunadb.Client({
|
|||
exports.handler = (event, context, callback) => {
|
||||
const data = JSON.parse(event.body)
|
||||
console.log('data', data)
|
||||
console.log("Function `todo-delete-batch` invoked", data.ids)
|
||||
console.log('Function `todo-delete-batch` invoked', data.ids)
|
||||
// construct batch query from IDs
|
||||
const deleteAllCompletedTodoQuery = data.ids.map((id) => {
|
||||
return q.Delete(q.Ref(`classes/todos/${id}`))
|
||||
})
|
||||
// Hit fauna with the query to delete the completed items
|
||||
return client.query(deleteAllCompletedTodoQuery)
|
||||
.then((response) => {
|
||||
console.log("success", response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
.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)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@ exports.handler = (event, context, callback) => {
|
|||
const id = getId(event.path)
|
||||
console.log(`Function 'todo-delete' invoked. delete id: ${id}`)
|
||||
return client.query(q.Delete(q.Ref(`classes/todos/${id}`)))
|
||||
.then((response) => {
|
||||
console.log("success", response)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
.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)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,28 +6,28 @@ const client = new faunadb.Client({
|
|||
})
|
||||
|
||||
exports.handler = (event, context, callback) => {
|
||||
console.log("Function `todo-read-all` invoked")
|
||||
return client.query(q.Paginate(q.Match(q.Ref("indexes/all_todos"))))
|
||||
.then((response) => {
|
||||
const todoRefs = response.data
|
||||
console.log("Todo refs", todoRefs)
|
||||
console.log(`${todoRefs.length} todos found`)
|
||||
// create new query out of todo refs. http://bit.ly/2LG3MLg
|
||||
const getAllTodoDataQuery = todoRefs.map((ref) => {
|
||||
return q.Get(ref)
|
||||
})
|
||||
// then query the refs
|
||||
return client.query(getAllTodoDataQuery).then((ret) => {
|
||||
console.log('Function `todo-read-all` invoked')
|
||||
return client.query(q.Paginate(q.Match(q.Ref('indexes/all_todos'))))
|
||||
.then((response) => {
|
||||
const todoRefs = response.data
|
||||
console.log('Todo refs', todoRefs)
|
||||
console.log(`${todoRefs.length} todos found`)
|
||||
// create new query out of todo refs. http://bit.ly/2LG3MLg
|
||||
const getAllTodoDataQuery = todoRefs.map((ref) => {
|
||||
return q.Get(ref)
|
||||
})
|
||||
// then query the refs
|
||||
return client.query(getAllTodoDataQuery).then((ret) => {
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(ret)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log('error', error)
|
||||
return callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(ret)
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@ exports.handler = (event, context, callback) => {
|
|||
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 callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
.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)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,17 +11,17 @@ exports.handler = (event, context, callback) => {
|
|||
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 callback(null, {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(response)
|
||||
.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)
|
||||
})
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.log("error", error)
|
||||
return callback(null, {
|
||||
statusCode: 400,
|
||||
body: JSON.stringify(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue