diff --git a/src/integrations/dynamodb.js b/src/integrations/dynamodb.js index d2d27f0..1c3721a 100644 --- a/src/integrations/dynamodb.js +++ b/src/integrations/dynamodb.js @@ -42,12 +42,20 @@ module.exports.getModSalesInLastYear = async (mod) => { return sortedResults } -module.exports.getLastSoldItems = async (source) => { +module.exports.getLastSoldItems = async (source, timeframeInDays) => { console.log("getLastSoldItems called") AWS.config.update({ region: "us-east-1" }) const ddb = new AWS.DynamoDB({ apiVersion: "2012-08-10" }) const responses = [] const oneDayAgo = new Date(new Date().getTime() - (24 * 60 * 60 * 1000)).toISOString() + const oneWeekAgo = new Date(new Date().getTime() - (7 * 24 * 60 * 60 * 1000)).toISOString() + let timeframe + + if (timeframeInDays === 1) { + timeframe = oneDayAgo + } else { + timeframe = oneWeekAgo + } const query = { TableName: "destiny-insights-items", @@ -55,7 +63,7 @@ module.exports.getLastSoldItems = async (source) => { ExpressionAttributeValues: { // AWS DynamoDB uses single char for types // eslint-disable-next-line id-length - ":startDate": { S: oneDayAgo }, + ":startDate": { S: timeframe }, // eslint-disable-next-line id-length ":source": { S: source } }, diff --git a/src/tweet-types/ada-1.js b/src/tweet-types/ada-1.js index a0ece30..14c0982 100644 --- a/src/tweet-types/ada-1.js +++ b/src/tweet-types/ada-1.js @@ -17,7 +17,7 @@ ${mod2Info} module.exports.ada1 = async () => { let result const { inventory: { mods: currentMods } } = await getVendorInventory("ada-1") - const lastSoldMods = await getLastSoldItems("ada-1") + const lastSoldMods = await getLastSoldItems("ada-1", 1) const newInventory = await isNewInventory(currentMods, lastSoldMods) if (newInventory) { diff --git a/src/tweet-types/banshee-44.js b/src/tweet-types/banshee-44.js index 265465e..dd1410f 100644 --- a/src/tweet-types/banshee-44.js +++ b/src/tweet-types/banshee-44.js @@ -17,7 +17,7 @@ ${mod2Info} module.exports.banshee44 = async () => { let result const { inventory: { mods: currentMods } } = await getVendorInventory("banshee-44") - const lastSoldMods = await getLastSoldItems("banshee-44") + const lastSoldMods = await getLastSoldItems("banshee-44", 1) const newInventory = await isNewInventory(currentMods, lastSoldMods) if (newInventory) { diff --git a/src/tweet-types/xur.js b/src/tweet-types/xur.js index 16d4e87..0565b1c 100644 --- a/src/tweet-types/xur.js +++ b/src/tweet-types/xur.js @@ -52,7 +52,7 @@ module.exports.xur = async () => { const { inventory: { armor, weapons } } = await getVendorInventory("xur") const currentInventory = [...weapons, ...armor] const exotics = currentInventory.filter((item) => item.type.startsWith("Exotic")) - const lastSoldItems = await getLastSoldItems("xur") + const lastSoldItems = await getLastSoldItems("xur", 7) const currentInventoryForCompare = getCompareStrings(exotics) const lastInventoryForCompare = getCompareStrings(lastSoldItems) const newInventory = await isNewInventory(currentInventoryForCompare, lastInventoryForCompare)