{"size": 1122, "ext": "js", "max_stars_repo_path": "createnote.js", "max_stars_repo_name": "jpotrymajlo/notes-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "createnote.js", "max_issues_repo_name": "jpotrymajlo/notes-api", "max_issues_repo_issues_event_min_datetime": "2021-04-11T21:11:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-11T21:15:56.000Z", "max_forks_repo_path": "createnote.js", "max_forks_repo_name": "jpotrymajlo/notes-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 24.9333333333, "max_line_length": 68, "alphanum_fraction": 0.5454545455}
import AWS from "aws-sdk";
import * as uuid from "uuid";

const dynamoDb = new AWS.DynamoDB.DocumentClient();

export const main = async (event, context, callback) => {

    const data = JSON.parse(event.body);
    const params = {
        TableName: process.env.tableName,
        Item: {
            userId: event.requestContext.identity.cognitoIdentityId,
            notesId: uuid.v1(),
            content: data,
            createAt: Date.now()
        }
    };

    const headers = {
        "Access-Control-Allow-Origin" : "*",
        "Access-Control-Allow-Credentials" : true
    };

    try {
        await dynamoDb.put(params).promise();

        const responseOk = {
            statusCode: 200,
            headers: headers,
            body: JSON.stringify(params.Item),
            isBase64Encoded: false
        };
        callback(null, responseOk);
    }
    catch (err){
        const responseFail = {
            statusCode: 500,
            headers: headers,
            body: JSON.stringify({error: err}),
            isBase64Encoded: false
        };
        callback(null, responseFail);
    }
};
