-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ceec6e
commit 56590ba
Showing
5 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import faunadb from 'faunadb' | ||
import getId from './utils/getId' | ||
|
||
const q = faunadb.query | ||
const client = new faunadb.Client({ | ||
secret: process.env.FAUNADB_SECRET | ||
}) | ||
|
||
exports.handler = (event, context, callback) => { | ||
const data = JSON.parse(event.body) | ||
console.log('data', data) | ||
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) | ||
}) | ||
}).catch((error) => { | ||
console.log("error", error) | ||
return callback(null, { | ||
statusCode: 400, | ||
body: JSON.stringify(error) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters