Created
April 23, 2020 19:08
-
-
Save digitalbase/33db556237ee88d818b732957a1f45e3 to your computer and use it in GitHub Desktop.
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
| const dynamoDBFactory = require('./src/dynamodb.factory'); | |
| const dynamoDb = dynamoDBFactory(); | |
| const { withStatusCode } = require('./src/utils/response.util'); | |
| const { parseWith } = require('./src/utils/request.util'); | |
| const parseJson = parseWith(JSON.parse); | |
| const ok = withStatusCode(200); | |
| const problem = withStatusCode(400); | |
| const IDENTIFY_TABLE = process.env.IDENTIFY_TABLE; | |
| const PAGE_TABLE = process.env.PAGE_TABLE; | |
| exports.handler = async (event) => { | |
| const request_body = parseJson(event.body); | |
| const { type, messageId } = request_body; | |
| if (type !== 'page' && type !== 'identify') { | |
| return ok('not a page'); | |
| } | |
| const params = { | |
| TableName: ( type === 'identify' ? IDENTIFY_TABLE : PAGE_TABLE), | |
| Item: { | |
| messageId, | |
| ...request_body | |
| }, | |
| }; | |
| try { | |
| await dynamoDb.put(params).promise(); | |
| } catch (e) { | |
| console.log('Could not store event', e); | |
| return problem(e.message); | |
| } | |
| return ok(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment