Skip to content

Instantly share code, notes, and snippets.

@connor11528
Created April 25, 2019 22:17
Show Gist options
  • Save connor11528/76acec63dc256d94dce9e41e765050b8 to your computer and use it in GitHub Desktop.
Save connor11528/76acec63dc256d94dce9e41e765050b8 to your computer and use it in GitHub Desktop.
Netlify function to add a salesperson to a Fauna database
require('dotenv').config()
const fauna = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SERVER_SECRET
});
exports.handler = (event, context, callback) => {
const data = JSON.parse(event.body)
const salesperson = {
data: data
};
return client.query(q.Create(q.Ref('classes/salesperson'), salesperson))
.then((response) => {
return callback(null, {
statusCode: 200,
body: JSON.stringify(response)
})
}).catch((error) => {
return callback(null, {
statusCode: 400,
body: JSON.stringify(error)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment