Skip to content

Commit

Permalink
Merge pull request #44 from poketrax/43-fix-issue-with-cards-not-show…
Browse files Browse the repository at this point in the history
…ing-in-collection-if-no-price-data-is-available

43 fix issue with cards not showing in collection if no price data is available
  • Loading branch information
jgunzelman88 authored Jun 11, 2022
2 parents ed80b04 + 33242cf commit 13d8747
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PokeTrax is an open source and free to use Pokémon TCG collection management to

## Downloads

[![Windows](assets/windows.png)](https://github.com/poketrax/PokeTrax/releases/download/v0.6.0-beta/PokeTrax.Setup.0.6.0.exe)[![MacOS](assets/macos.png)](https://github.com/poketrax/PokeTrax/releases/download/v0.6.0-beta/PokeTrax-0.6.0.dmg)
[![Windows](assets/windows.png)](https://github.com/poketrax/PokeTrax/releases/download/v0.6.1-beta/PokeTrax.Setup.0.6.1.exe)[![MacOS](assets/macos.png)](https://github.com/poketrax/PokeTrax/releases/download/v0.6.1-beta/PokeTrax-0.6.1.dmg)

## Install Instructions:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "poketrax",
"productName": "PokeTrax",
"version": "0.6.0",
"version": "0.6.1",
"main": "src/server/main.js",
"homepage": ".",
"private": true,
Expand Down
36 changes: 29 additions & 7 deletions src/server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ const dbStatus = () => {
}

const checkForDbUpdate = () => {
// updateCollections()
// updateCollections()
return new Promise(
async (resolve, reject) => {
//search for folder

if (fs.existsSync(path.join(pwd(), "./sql")) === false) {
fs.mkdirSync(path.join(pwd(), "./sql"), {recursive: true})
fs.mkdirSync(path.join(pwd(), "./sql"), { recursive: true })
}
//Init databases
let meta = await pullDbMeta()

//if new and no meta file exists
if (fs.existsSync(path.join(pwd(), DB_META)) === false) {
dbUpdate = { ready: false, updated: true }
Expand Down Expand Up @@ -144,13 +144,13 @@ async function pullDb(meta) {
//write database file
let writer = fs.createWriteStream(path.join(pwd(), CARD_DB_FILE))
stream.pipe(writer)

writer.on('finish', () => {
fs.writeFileSync(path.join(pwd(), "./sql/meta.json"), JSON.stringify(meta))
dbUpdate = { ready: true, updated: true }
resolve()
})
writer.on('error', () => { console.log("ERROR");reject() })
writer.on('error', () => { console.log("ERROR"); reject() })
})
}
)
Expand All @@ -162,14 +162,36 @@ async function pullDb(meta) {
* @returns
*/
function getTcgpPrice(card) {
console.log("call tcgp")
console.log("Call TCGP")
let db = pricesDB()
return new Promise(
(resolve, reject) => {
axios.get(`https://infinite-api.tcgplayer.com/price/history/${card.idTCGP}?range=month`).then(
(res) => {
let prices = []
if (res.data.count === 0) {
console.log("price")
for (let variant of JSON.parse(card.variants)) {
let price = {
"date": Date.now(),
"cardId": card.cardId,
"variant": variant,
"vendor": "tcgp",
"price": 0.0
}
let sql = `INSERT OR IGNORE INTO prices
(id, date, cardId, variant, vendor, price)
VALUES ($id, $date, $cardId, $variant, $vendor, $price)`
db.prepare(sql).run({
"id": hash(price.date + card.cardId + variant + "tcgp"),
"date": price.date,
"cardId": price.cardId,
"variant": variant,
"vendor": price.vendor,
"price": price.price
})
prices.push(price)
}
resolve(prices)
}
for (let result of res.data.result) {
Expand Down

0 comments on commit 13d8747

Please sign in to comment.