get-devices
unknown
javascript
9 months ago
1.0 kB
12
Indexable
async function getDevices({
warehouse_id,
lastEvaluatedKey,
limit = 10
}) {
try {
const queryParams = {
TableName: process.env.DEVICE_TABLE,
KeyConditionExpression: "warehouse_id = :warehouse_id",
ExpressionAttributeValues: {
":warehouse_id": { S: warehouse_id }
},
Limit: limit
};
if (lastEvaluatedKey) {
queryParams.ExclusiveStartKey = lastEvaluatedKey;
}
const result = await dynamodb2.send(new import_client_dynamodb2.QueryCommand(queryParams));
const response = {
items: result.Items || [],
lastEvaluatedKey: result.LastEvaluatedKey || null
};
return {
statusCode: 200,
body: JSON.stringify(response),
headers: headers2
};
} catch (error) {
console.error("Error querying device data:", error);
return {
statusCode: 500,
body: JSON.stringify({ message: "Could not fetch device data" + error }),
headers: headers2
};
}
}Editor is loading...
Leave a Comment