Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

add else blocks and nicer comments for fauna example #51

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/functions-templates/js/fauna-crud/fauna-crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,45 @@ exports.handler = async (event, context) => {

switch (event.httpMethod) {
case 'GET':
// e.g. GET /.netlify/functions/fauna-crud
if (segments.length === 0) {
return require('./read-all').handler(event, context)
}
// e.g. GET /.netlify/functions/fauna-crud/123456
if (segments.length === 1) {
event.id = segments[0]
return require('./read').handler(event, context)
} else {
return {
statusCode: 500,
body:
'too many segments in GET request, must be either /.netlify/functions/fauna-crud or /.netlify/functions/fauna-crud/123456'
}
}
case 'POST':
// e.g. POST /.netlify/functions/fauna-crud with a body of key value pair objects, NOT strings
return require('./create').handler(event, context)
case 'PUT':
// e.g. PUT /.netlify/functions/fauna-crud/123456 with a body of key value pair objects, NOT strings
if (segments.length === 1) {
event.id = segments[0]
return require('./update').handler(event, context)
} else {
return {
statusCode: 500,
body: 'invalid segments in POST request, must be /.netlify/functions/fauna-crud/123456'
}
}
case 'DELETE':
// e.g. DELETE /.netlify/functions/fauna-crud/123456
if (segments.length === 1) {
event.id = segments[0]
return require('./delete').handler(event, context)
} else {
return {
statusCode: 500,
body: 'invalid segments in DELETE request, must be /.netlify/functions/fauna-crud/123456'
}
}
}
return { statusCode: 500, body: 'unrecognized HTTP Method, must be one of GET/POST/PUT/DELETE' }
Expand Down