Files
gemory/src/reprocess/reprocess.ts
T
2026-06-19 23:05:42 +02:00

30 lines
1.0 KiB
TypeScript

import { reprocessingApi } from '@/mammon';
import { getMarketTypes } from '@/market';
export type ReprocessItemValues = {
typeID: number;
name: string;
buy: number;
buy_reprocess: number;
sell: number;
sell_reprocess: number;
}
export const reprocess = async (characterId?: number, items?: string, locationId?: number): Promise<ReprocessItemValues[]> => {
if (!characterId || !items?.trim()) {
return [];
}
const results = await reprocessingApi.reprocessRawItems(characterId, items, locationId).then(r => r.data);
const names = await getMarketTypes(results.map(r => r.input.marketTypeId))
.then(types => new Map(types.map(t => [t.id, t.name])));
return results.map(({ input, output }) => ({
typeID: input.marketTypeId,
name: names.get(input.marketTypeId) ?? '',
buy: input.buy,
sell: input.sell,
buy_reprocess: output.reduce((sum, o) => sum + o.buy, 0),
sell_reprocess: output.reduce((sum, o) => sum + o.sell, 0),
}));
};