init commit ⊂◉‿◉つ

This commit is contained in:
davidwells 2018-06-11 15:48:00 -07:00
commit c8c51623a6
19 changed files with 7568 additions and 0 deletions

20
functions/todos-create.js Normal file
View file

@ -0,0 +1,20 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
const data = JSON.parse(event.body);
console.log("create todo", data);
return client.query(q.Create(q.Ref("classes/todos"), {data}))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};

19
functions/todos-delete.js Normal file
View file

@ -0,0 +1,19 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
console.log("delete todo");
return client.query(q.Delete(q.Ref("classes/todos/"+event.pathParameters.id)))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};

View file

@ -0,0 +1,19 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
console.log("readAll todo");
return client.query(q.Paginate(q.Match(q.Ref("indexes/all_todos"))))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};

View file

@ -0,0 +1,19 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
console.log("readOne todo "+event.pathParameters.id);
return client.query(q.Get(q.Ref("classes/todos/"+event.pathParameters.id)))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};

20
functions/todos-update.js Normal file
View file

@ -0,0 +1,20 @@
'use strict';
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
const data = JSON.parse(event.body);
console.log("update todo");
return client.query(q.Update(q.Ref("classes/todos/"+event.pathParameters.id), {data}))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};