-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
35 lines (31 loc) · 1.04 KB
/
db.js
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
34
35
const AWS = require("aws-sdk");
const dynamoDb = new AWS.DynamoDB.DocumentClient();
/**
* Function to store sneaker and user data into DynamoDB
* @param {Object} sneaker - The sneaker object containing price and metadata
* @param {Object} event - The event containing email, styleID, priceTarget, and notify
*/
async function storeSneakerData(sneaker, event) {
const params = {
TableName: "SneakerNotifications",
Item: {
email: event.email,
styleID: sneaker.styleID,
price: sneaker.price,
priceTarget: event.priceTarget || 100,
notify: event.notify !== undefined ? event.notify : true,
site: sneaker.site,
url: sneaker.url,
name: sneaker.name,
timestamp: new Date().toISOString(),
},
};
try {
await dynamoDb.put(params).promise();
console.log("Data stored successfully in DynamoDB");
} catch (error) {
console.error("Error storing data in DynamoDB:", error);
throw new Error("DynamoDB storage failed: " + error.message);
}
}
module.exports = { storeSneakerData };