1- import uuid from "uuid" ;
2- import * as dynamoDbLib from "./libs/dynamodb -lib" ;
3- import { success , failure } from "./libs/response -lib" ;
1+ import * as uuid from "uuid" ;
2+ import handler from "./libs/handler -lib" ;
3+ import dynamoDb from "./libs/dynamodb -lib" ;
44
5- export async function main ( event , context ) {
5+ export const main = handler ( async ( event , context ) => {
66 const data = JSON . parse ( event . body ) ;
77 const params = {
88 TableName : process . env . tableName ,
9+ // 'Item' contains the attributes of the item to be created
10+ // - 'userId': user identities are federated through the
11+ // Cognito Identity Pool, we will use the identity id
12+ // as the user id of the authenticated user
13+ // - 'noteId': a unique uuid
14+ // - 'content': parsed from request body
15+ // - 'attachment': parsed from request body
16+ // - 'createdAt': current Unix timestamp
917 Item : {
1018 userId : event . requestContext . identity . cognitoIdentityId ,
1119 noteId : uuid . v1 ( ) ,
@@ -15,10 +23,7 @@ export async function main(event, context) {
1523 }
1624 } ;
1725
18- try {
19- await dynamoDbLib . call ( "put" , params ) ;
20- return success ( params . Item ) ;
21- } catch ( e ) {
22- return failure ( { status : false } ) ;
23- }
24- }
26+ await dynamoDb . put ( params ) ;
27+
28+ return params . Item ;
29+ } ) ;
0 commit comments