diff --git a/package-lock.json b/package-lock.json index c95abe6..12390d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "knight-companion", - "version": "2.1.0", + "version": "2.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1952,9 +1952,9 @@ } }, "cmdr-journal": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/cmdr-journal/-/cmdr-journal-7.0.1.tgz", - "integrity": "sha512-PncmqJeUETzM7+0Duxyia6eMC/xh7NO9RZ0RWGMM+ApIzYpAdJy5XJU/SxfogIAN28JyF2SgIYYVzZmM66ZmXQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/cmdr-journal/-/cmdr-journal-7.1.1.tgz", + "integrity": "sha512-vpWqC0W7AVjMTWQ2lZiCcGO2FSwr//vajY3+h4HuD0rz8hOBU2222JfWounCZIXZCt8U9IGXaAqrmQ09rtRvyg==", "dev": true }, "co": { diff --git a/package.json b/package.json index ed8bbae..5e1ad97 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@types/semver": "^5.5.0", "angular2-template-loader": "^0.6.2", "awesome-typescript-loader": "^5.2.1", - "cmdr-journal": "^7.0.1", + "cmdr-journal": "^7.1.1", "copy-webpack-plugin": "^5.1.1", "cross-env": "^5.2.0", "css-loader": "^1.0.1", diff --git a/src/app/journal/eddn-commodities.model.ts b/src/app/journal/eddn-commodities.model.ts new file mode 100644 index 0000000..62ddcdf --- /dev/null +++ b/src/app/journal/eddn-commodities.model.ts @@ -0,0 +1,10 @@ +type EDDNCommodity = { + name: string; + meanPrice: number; + buyPrice: number; + stock: number; + stockBracket: number; + sellPrice: number; + demand: number; + demandBracket: number; +}; diff --git a/src/app/journal/eddn.service.ts b/src/app/journal/eddn.service.ts index 5c5ca82..b5319df 100644 --- a/src/app/journal/eddn.service.ts +++ b/src/app/journal/eddn.service.ts @@ -6,6 +6,7 @@ import { Location, CarrierJump, MarketJSON, + COMMODITY_MAP, } from "cmdr-journal"; import { HttpClient } from "@angular/common/http"; import { LoggerService } from "../core/services/logger.service"; @@ -134,6 +135,34 @@ export class EDDNService { } delete marketData.event; + const commodityData: EDDNCommodity[] = []; + + marketData.Items.forEach((item) => { + const commoditySymbol = COMMODITY_MAP.get(item.id)?.symbol; + + if ( + commoditySymbol && + !isNaN(item.MeanPrice) && + !isNaN(item.BuyPrice) && + !isNaN(item.Stock) && + !isNaN(item.StockBracket) && + !isNaN(item.SellPrice) && + !isNaN(item.Demand) && + !isNaN(item.DemandBracket) + ) { + commodityData.push({ + name: commoditySymbol, + meanPrice: item.MeanPrice, + buyPrice: item.BuyPrice, + stock: item.Stock, + stockBracket: item.StockBracket, + sellPrice: item.SellPrice, + demand: item.Demand, + demandBracket: item.DemandBracket, + }); + } + }); + let submission = { $schemaRef: process.env.EDDN_COMMODITY_ENDPOINT, header: { @@ -146,16 +175,7 @@ export class EDDNService { stationName: marketData.StationName, marketId: marketData.MarketID, timestamp: marketData.timestamp, - commodities: marketData.Items.map((item) => ({ - name: item.Name, - meanPrice: item.MeanPrice, - buyPrice: item.BuyPrice, - stock: item.Stock, - stockBracket: item.StockBracket, - sellPrice: item.SellPrice, - demand: item.Demand, - demandBracket: item.DemandBracket, - })), + commodities: commodityData, }, };