async function handler()

in src/books/get-all/index.ts [22:57]


async function handler(): Promise<APIGatewayProxyResult> {
  let response: APIGatewayProxyResult;
  try {
    const client = new AWS.DynamoDB(ddbOptions);

    const params: AWS.DynamoDB.Types.ScanInput = {
      TableName: process.env.TABLE || 'books'
    };

    const result: AWS.DynamoDB.Types.ScanOutput = await client.scan(params).promise();

    const bookDtos = result.Items?.map(item => ({
      isbn: item['isbn'].S,
      title: item['title'].S,
      year: parseInt(item['year'].N!, 10),
      author: item['author'].S,
      publisher: item['publisher'].S,
      rating: parseInt(item['rating'].N!, 10),
      pages: parseInt(item['pages'].N!, 10)
    }));

    response = {
      statusCode: 200,
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(bookDtos)
    };

  } catch (e) {
    response = {
      statusCode: 500,
      headers: {},
      body: ''
    };
  }
  return response;
}