diff --git a/serverless/packages/functions/src/trainspace/get_all_trainspace.ts b/serverless/packages/functions/src/trainspace/get_all_trainspace.ts index 40e2ec86c..f83619ff8 100644 --- a/serverless/packages/functions/src/trainspace/get_all_trainspace.ts +++ b/serverless/packages/functions/src/trainspace/get_all_trainspace.ts @@ -11,21 +11,29 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => { const client: DynamoDBClient = new DynamoDBClient({}); const docClient: DynamoDBDocumentClient = DynamoDBDocumentClient.from(client); - - const getCommand = new QueryCommand({ - TableName: "trainspace", - IndexName: "uid", - KeyConditionExpression: "uid = :uid", - ExpressionAttributeValues: { - ":uid" : - { - S: user_id - } - } - }); + const fetchedTrainspaceIds: Array = []; + let lastEvaluatedKey = undefined; - const results = await docClient.send(getCommand); - const fetchedTrainspaceIds = results['Items']?.map(trainspace => trainspace['trainspace_id'].S); + do { + const getCommand = new QueryCommand({ + TableName: "trainspace", + IndexName: "uid", + KeyConditionExpression: "uid = :uid", + ExpressionAttributeValues: { + ":uid" : + { + S: user_id + } + }, + ExclusiveStartKey: lastEvaluatedKey + }); + + const results = await docClient.send(getCommand); + lastEvaluatedKey = results.LastEvaluatedKey; + const page: Array = results['Items']?.map(trainspace => trainspace['trainspace_id'].S); + page.forEach(id => fetchedTrainspaceIds.push(id)); + + } while (lastEvaluatedKey !== undefined); return { statusCode: 200, body: JSON.stringify({ trainspace_ids : fetchedTrainspaceIds})