18 lines
657 B
TypeScript
18 lines
657 B
TypeScript
import {MarketType} from "../type";
|
|
import {MarketTypePrice} from './MarketTypePrice';
|
|
import {getMammonPrices} from './mammon';
|
|
|
|
const BATCH_SIZE = 100;
|
|
|
|
export const getPrice = async (type: MarketType, locationId?: number): Promise<MarketTypePrice> => (await getPrices([type], locationId))[0];
|
|
|
|
export const getPrices = async (types: MarketType[], locationId?: number): Promise<MarketTypePrice[]> => {
|
|
const batches: Promise<MarketTypePrice[]>[] = [];
|
|
|
|
for (let i = 0; i < types.length; i += BATCH_SIZE) {
|
|
batches.push(getMammonPrices(types.slice(i, i + BATCH_SIZE), locationId));
|
|
}
|
|
|
|
return (await Promise.all(batches)).flat();
|
|
};
|