get All Operators
unknown
javascript
25 days ago
1.2 kB
2
Indexable
async function getAllOperators(limit, lastEvaluatedKey) { try { const scanParams = { TableName: process.env.OPERATOR_TABLE }; if (limit) { scanParams.Limit = parseInt(limit); } if (lastEvaluatedKey) { scanParams.ExclusiveStartKey = await JSON.parse(decodeURIComponent(lastEvaluatedKey)); } const result = await dynamodb.send( new import_lib_dynamodb.ScanCommand(scanParams) ); if (!result.Items || result.Items.length === 0) { return { statusCode: 404, body: JSON.stringify({ message: "No operators found" }), headers }; } const items = result.Items; for (const item of items) { const user = await getUser(item.user_id); item.user = await JSON.parse(user.body || "{}"); } return { statusCode: 200, body: JSON.stringify({ items, lastEvaluatedKey: result.LastEvaluatedKey || null }), headers }; } catch (error) { console.error("Error getting operators:", error); return { statusCode: 500, body: JSON.stringify({ message: "Error fetching operators: " + error }), headers }; } }
Editor is loading...
Leave a Comment