Skip to content

Commit

Permalink
volume and median keys are not always provided by the API
Browse files Browse the repository at this point in the history
  • Loading branch information
lenovouser committed May 6, 2017
1 parent 4c56ee2 commit 2761fad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface Price {
/**
* Median Price On The [Steam Community Market](https://steamcommunity.com/market/)
*/
median: number;
median?: number;
}

/**
Expand All @@ -72,7 +72,7 @@ export interface CleanItem {
/**
* Number Of Available Skins On The Steam Market
*/
volume: number;
volume?: number;
}

/**
Expand All @@ -86,15 +86,15 @@ export interface RawItem {
/**
* Median Price On The [Steam Community Market](https://steamcommunity.com/market/)
*/
median_price: string;
median_price?: string;
/**
* Wether the request was successful or not
*/
success: boolean;
/**
* Number Of Available Skins On The Steam Market
*/
volume: string;
volume?: string;
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,23 @@ const determineCurrencySign = (currency: number): string => {
* @hidden
*/
export const generateItem = (name: string, response: RawItem, currency: number): Item => {
const result = {
const result: Item = {
id: name,
price: {
code: determineCurrencyCode(currency),
lowest: unformat(response.lowest_price),
median: unformat(response.median_price),
sign: determineCurrencySign(currency),
type: determineCurrencyType(currency),
},
volume: parseInt(response.volume, 10),
};

if (response.median_price) {
result.price.median = unformat(response.median_price);
}

if (response.volume) {
result.volume = parseInt(response.volume, 10);
}

return result;
};

0 comments on commit 2761fad

Please sign in to comment.