-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.ts
30 lines (26 loc) · 1.01 KB
/
handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'source-map-support/register';
import { middyfy } from '@libs/lambda';
import { createLogger } from '@libs/logger'
import type { APIGatewayProxyEvent, APIGatewayProxyResult, APIGatewayProxyHandler } from "aws-lambda"
import { getUserId } from '@libs/getUserId';
import {getItems} from '@libs/database'
const logger = createLogger('getTodos')
/**
* lambda function to retrieve user todo items from db
* @param event
* @returns a JSON with all the items retrieved from db
*/
const getTodos: APIGatewayProxyHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
// TODO: Get all TODO items for a current user
const userId = await getUserId(event);
logger.info(`Retrieving TODO items for user ${userId}`);
const todos = await getItems(userId);
return {
statusCode: 201,
body: JSON.stringify({
items: todos
})
};
}
// wrap this handler around the middy middleware
export const main = middyfy(getTodos);