-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.ts
More file actions
33 lines (30 loc) · 801 Bytes
/
list.ts
File metadata and controls
33 lines (30 loc) · 801 Bytes
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
31
32
33
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'
import ServiceError from './lib/ServiceError'
import { handleErrorResponse } from './lib/error'
import Task from './model/Task'
export const handler = async (
event: APIGatewayProxyEvent
): Promise<APIGatewayProxyResult> => {
try {
const tableName = process.env.DYNAMODB_TABLE
if (!tableName) {
throw new ServiceError(
'DYNAMODB_TABLE environment variable not defined',
500
)
}
const task = new Task(tableName)
const tasks = await task.list()
return {
statusCode: 200,
body: JSON.stringify({
tasks,
}),
headers: {
'Content-Type': 'application/json',
},
}
} catch (error) {
return handleErrorResponse(error)
}
}