Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
fix: adds back different timeframes to last sold lookups (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
cujarrett authored Jan 1, 2022
1 parent e2ac273 commit d34ad76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/integrations/dynamodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,28 @@ 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",
FilterExpression: "#ts > :startDate AND #s = :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 }
},
Expand Down
2 changes: 1 addition & 1 deletion src/tweet-types/ada-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/tweet-types/banshee-44.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/tweet-types/xur.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d34ad76

Please sign in to comment.