get orders

This commit is contained in:
2023-09-16 13:02:24 +02:00
parent 3de8f53e0f
commit c1f00da176
5 changed files with 46 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
<script setup lang="ts">
import { evepraisalAxiosInstance } from '@/service';
import { useStorage } from '@vueuse/core';
import { onMounted, ref, watch } from 'vue';
import { MarketOrderHistory, MarketResult, getHistory, jitaId } from ".";
@@ -15,8 +16,16 @@ const itemsStorage = useStorage<MarketItemStorage[]>('market-items', []);
const items = ref<MarketResult[]>([]);
const addOrRelaod = async (type: MarketType) => {
const typeID = type.id;
const history = await getHistory(jitaId, typeID);
const item = { type, history };
const [history, price] = await Promise.all([
getHistory(jitaId, typeID),
evepraisalAxiosInstance.post('/appraisal.json?market=jita&persist=no', type.name)
]);
const item = {
type,
history,
buy: price.data.appraisal.items[0].prices.buy.max,
sell: price.data.appraisal.items[0].prices.sell.min
};
if (items.value.some(i => i.type.id === typeID)) {
items.value = items.value.map(i => i.type.id === typeID ? item : i);
@@ -37,9 +46,20 @@ const addItem = async () => {
watch(items, itms => itemsStorage.value = itms.map(i => ({ typeID: i.type.id, history: i.history })));
onMounted(async () => {
const types = await getMarketTypes(itemsStorage.value.map(i => i.typeID));
const prices: any = (await evepraisalAxiosInstance.post(`/appraisal.json?market=jita&persist=no&raw_textarea=${types.map(t => t.name).join("%0A")}`)).data;
items.value = itemsStorage.value.map(i => ({ ...i, type: types.find(t => t.id === i.typeID) as MarketType }));
})
items.value = itemsStorage.value.map(i => {
const type = types.find(t => t.id === i.typeID) as MarketType;
const price = prices.appraisal.items.find((p: any) => p.typeID === i.typeID);
return {
...i,
type: type,
buy: price.prices.buy.max,
sell: price.prices.sell.min
};
});
});
</script>
<template>