diff --git a/scripts/pokemon-helper.ts b/scripts/pokemon-helper.ts index 6de5701..9db7ff3 100644 --- a/scripts/pokemon-helper.ts +++ b/scripts/pokemon-helper.ts @@ -106,6 +106,7 @@ export const createInventoryCollection = async () => { { name: 'catalogName', type: 'string' }, { name: 'card_id', type: 'string', reference: 'cards.id', async_reference: true }, { name: 'sku_id', type: 'string', reference: 'skus.id', async_reference: true }, + { name: 'purchasePrice', type: 'int32', optional: true }, // content,setName,productLineName,rarityName,energyType,cardType from cards for searching { name: 'content', type: 'string', token_separators: ['/'] }, { name: 'setName', type: 'string' }, @@ -172,6 +173,7 @@ export const upsertInventoryCollection = async (db:DBInstance) => { catalogName: i.catalogName, card_id: i.sku?.cardId.toString(), sku_id: i.skuId.toString(), + purchasePrice: DollarToInt(i.purchasePrice), productLineName: i.sku?.card?.productLineName, rarityName: i.sku?.card?.rarityName, setName: i.sku?.card?.set?.setName || "", diff --git a/src/pages/api/inventory.ts b/src/pages/api/inventory.ts index c055968..b48e1f0 100644 --- a/src/pages/api/inventory.ts +++ b/src/pages/api/inventory.ts @@ -12,6 +12,10 @@ const GainLoss = (purchasePrice: any, marketPrice: any) => { if (pp > mp) return `
-$${(pp - mp).toFixed(2)}
`; return `
+$${(mp - pp).toFixed(2)}
`; } +const DollarToInt = (dollar: any) => { + if (dollar === null) return null; + return Math.round(dollar * 100); +} const getInventory = async (userId: string, cardId: number) => { @@ -108,6 +112,7 @@ const addToInventory = async (userId: string, cardId: number, skuId: number, pur userId: i.userId, catalogName: i.catalogName, sku_id: i.skuId.toString(), + purchasePrice: DollarToInt(i.purchasePrice), productLineName: card?.productLineName, rarityName: card?.rarityName, setName: card?.set?.setName || "",