forked from sebastien-lb/japcalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave-db.js
34 lines (32 loc) · 1.04 KB
/
save-db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const faunadb = require("faunadb"); /* Import faunaDB sdk */
/* configure faunaDB Client with our secret */
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SERVER_SECRET,
});
exports.handler = async function(event, context) {
const data = JSON.parse(event.body);
console.log("Function `todo-create` invoked", data);
const todoItem = {
data: data,
};
/* construct the fauna query */
return client
.query(q.Create(q.Ref("classes/todos"), todoItem))
.then((response) => {
console.log("success", response);
/* Success! return the response with statusCode 200 */
return {
statusCode: 200,
body: JSON.stringify(response),
};
})
.catch((error) => {
console.log("error", error);
/* Error! return the error with statusCode 400 */
return {
statusCode: 400,
body: JSON.stringify(error),
};
});
};