Created
April 25, 2019 22:17
-
-
Save connor11528/76acec63dc256d94dce9e41e765050b8 to your computer and use it in GitHub Desktop.
Netlify function to add a salesperson to a Fauna database
This file contains hidden or 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
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