From 7332e145f41a98d57c98bcb6550c8b2d8961711a Mon Sep 17 00:00:00 2001 From: Sirttas Date: Tue, 14 May 2024 21:21:17 +0200 Subject: [PATCH] draft acquisition --- src/market/acquisition/AcquiredItem.ts | 8 +++ .../AcquisitionQuantilsTooltip.vue} | 0 .../AcquisitionResultTable.vue} | 18 ++--- .../{track => acquisition}/BuyModal.vue | 8 +-- .../{track => acquisition}/SellModal.vue | 8 +-- src/market/acquisition/acquisition.ts | 65 +++++++++++++++++++ src/market/acquisition/index.ts | 7 ++ src/market/track/TrackedItem.ts | 9 --- src/market/track/index.ts | 7 -- src/market/track/track.ts | 58 ----------------- src/pages/Market.vue | 4 +- src/pages/market/Acquisitions.vue | 43 ++++++++++++ src/pages/market/Scan.vue | 6 +- src/pages/market/Track.vue | 38 ----------- src/routes.ts | 2 +- 15 files changed, 146 insertions(+), 135 deletions(-) create mode 100644 src/market/acquisition/AcquiredItem.ts rename src/market/{track/TrackQuantilsTooltip.vue => acquisition/AcquisitionQuantilsTooltip.vue} (100%) rename src/market/{track/TrackResultTable.vue => acquisition/AcquisitionResultTable.vue} (88%) rename src/market/{track => acquisition}/BuyModal.vue (91%) rename src/market/{track => acquisition}/SellModal.vue (85%) create mode 100644 src/market/acquisition/acquisition.ts create mode 100644 src/market/acquisition/index.ts delete mode 100644 src/market/track/TrackedItem.ts delete mode 100644 src/market/track/index.ts delete mode 100644 src/market/track/track.ts create mode 100644 src/pages/market/Acquisitions.vue delete mode 100644 src/pages/market/Track.vue diff --git a/src/market/acquisition/AcquiredItem.ts b/src/market/acquisition/AcquiredItem.ts new file mode 100644 index 0000000..b6debaf --- /dev/null +++ b/src/market/acquisition/AcquiredItem.ts @@ -0,0 +1,8 @@ +import { MarketType } from ".."; +import { AcquiredMarketItem } from "./acquisition"; + +export type AcquiredItem = Omit & { + type: MarketType, + buy: number, + sell: number +} \ No newline at end of file diff --git a/src/market/track/TrackQuantilsTooltip.vue b/src/market/acquisition/AcquisitionQuantilsTooltip.vue similarity index 100% rename from src/market/track/TrackQuantilsTooltip.vue rename to src/market/acquisition/AcquisitionQuantilsTooltip.vue diff --git a/src/market/track/TrackResultTable.vue b/src/market/acquisition/AcquisitionResultTable.vue similarity index 88% rename from src/market/track/TrackResultTable.vue rename to src/market/acquisition/AcquisitionResultTable.vue index ea56d62..7c77711 100644 --- a/src/market/track/TrackResultTable.vue +++ b/src/market/acquisition/AcquisitionResultTable.vue @@ -5,8 +5,8 @@ import { MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/mark import { MinusIcon, PlusIcon } from '@heroicons/vue/24/outline'; import { useStorage } from '@vueuse/core'; import { computed, ref } from 'vue'; -import { TrackedItem } from '.'; -import TrackQuantilsTooltip from './TrackQuantilsTooltip.vue'; +import { AcquiredItem } from './AcquiredItem'; +import AcquisitionQuantilsTooltip from './AcquisitionQuantilsTooltip.vue'; type Result = { type: MarketType; @@ -21,7 +21,7 @@ type Result = { } interface Props { - items?: TrackedItem[]; + items?: AcquiredItem[]; } interface Emits { @@ -36,12 +36,12 @@ defineEmits(); const marketTaxStore = useMarketTaxStore(); -const threshold = useStorage('market-track-threshold', 10); +const threshold = useStorage('market-axquisition-threshold', 10); const filter = ref(""); const { sortedArray, headerProps } = useSort(computed(() => props.items .filter(r => r.type.name.toLowerCase().includes(filter.value.toLowerCase())) .map(r => { - const precentProfit = marketTaxStore.calculateProfit(r.averagePrice, r.sell); + const precentProfit = marketTaxStore.calculateProfit(r.price, r.sell); return { type: r.type, @@ -49,10 +49,10 @@ const { sortedArray, headerProps } = useSort(computed(() => props.items name: r.type.name, buy: r.buy, sell: r.sell, - price: r.averagePrice, - count: r.count, + price: r.price, + count: r.remaining, precentProfit, - iskProfit: r.averagePrice * precentProfit * r.count + iskProfit: r.price * precentProfit * r.remaining }; })), { defaultSortKey: 'precentProfit', @@ -100,7 +100,7 @@ const getLineColor = (result: Result) => {
- +
{{ formatIsk(r.buy) }} diff --git a/src/market/track/BuyModal.vue b/src/market/acquisition/BuyModal.vue similarity index 91% rename from src/market/track/BuyModal.vue rename to src/market/acquisition/BuyModal.vue index 23b0847..41d7b5c 100644 --- a/src/market/track/BuyModal.vue +++ b/src/market/acquisition/BuyModal.vue @@ -3,10 +3,10 @@ import { Modal } from '@/components'; import { formatIsk } from '@/formaters'; import { MarketType, MarketTypeLabel } from '@/market'; import { ref } from 'vue'; -import { useTrackedItemStore } from './track'; +import { useAcquiredItemStore } from './acquisition'; -const trackedItemStore = useTrackedItemStore(); +const acquiredItemStore = useAcquiredItemStore(); const modalOpen = ref(false); const type = ref(); @@ -38,7 +38,7 @@ const add = () => { return; } - trackedItemStore.addTrackedItem(id, count.value, price.value); + acquiredItemStore.addAcquiredItem(id, count.value, price.value); modalOpen.value = false; } @@ -66,4 +66,4 @@ defineExpose({ open }); - \ No newline at end of file +./acquisitions \ No newline at end of file diff --git a/src/market/track/SellModal.vue b/src/market/acquisition/SellModal.vue similarity index 85% rename from src/market/track/SellModal.vue rename to src/market/acquisition/SellModal.vue index ae370dc..e61cdd6 100644 --- a/src/market/track/SellModal.vue +++ b/src/market/acquisition/SellModal.vue @@ -2,10 +2,10 @@ import { Modal } from '@/components'; import { MarketType, MarketTypeLabel } from '@/market'; import { ref } from 'vue'; -import { useTrackedItemStore } from './track'; +import { useAcquiredItemStore } from './acquisition'; -const trackedItemStore = useTrackedItemStore(); +const acquiredItemStore = useAcquiredItemStore(); const modalOpen = ref(false); const type = ref(); @@ -24,7 +24,7 @@ const remove = () => { return; } - trackedItemStore.removeTrackedItem(id, count.value); + acquiredItemStore.removeAcquiredItem(id, count.value); modalOpen.value = false; } @@ -45,4 +45,4 @@ defineExpose({ open }); - \ No newline at end of file +./acquisitions \ No newline at end of file diff --git a/src/market/acquisition/acquisition.ts b/src/market/acquisition/acquisition.ts new file mode 100644 index 0000000..baf79f0 --- /dev/null +++ b/src/market/acquisition/acquisition.ts @@ -0,0 +1,65 @@ +import { marbasAxiosInstance } from "@/service"; +import { defineStore } from "pinia"; +import { computed, onMounted, ref } from "vue"; + +export type AcquiredMarketItem = { + id: number; + type: number; + quantity: number; + remaining: number; + price: number; + date: Date; + source: 'bo' | 'so' | 'prod'; + user: number; +} + +const endpoint = '/api/acquisitions'; + +export const useAcquiredItemStore = defineStore('market-acquisition', () => { + const _acquiredItems = ref([]); + + const items = computed(() => _acquiredItems.value); + const addAcquiredItem = async (type: number, quantity: number, price: number) => { + _acquiredItems.value = [..._acquiredItems.value, (await marbasAxiosInstance.post(endpoint, { + type: type, + quantity: quantity, + remaining: quantity, + price: price, + date: new Date(), + source: 'bo', + user: 0 // TODO: get user id + })).data]; + }; + const removeAcquiredItem = async (type: number, quantity: number) => { + const found = _acquiredItems.value.find(item => item.type === type); + + if (!found) { + return; + } + if (found.remaining <= 0) { + _acquiredItems.value = _acquiredItems.value.filter(i => i.type !== type); + + await marbasAxiosInstance.delete(`${endpoint}/${found.id}`); + } else { + const item = { + ...found, + remaining: found.remaining - quantity + }; + + _acquiredItems.value = _acquiredItems.value.map(i => { + if (i.type === item.type) { + return item; + } else { + return i; + } + }); + await marbasAxiosInstance.put(`${endpoint}/${item.id}`, item); + } + }; + + onMounted(async () => { + _acquiredItems.value = (await marbasAxiosInstance.get(endpoint)).data; + }); + + return { items, addAcquiredItem, removeAcquiredItem }; +}); \ No newline at end of file diff --git a/src/market/acquisition/index.ts b/src/market/acquisition/index.ts new file mode 100644 index 0000000..6768d05 --- /dev/null +++ b/src/market/acquisition/index.ts @@ -0,0 +1,7 @@ +export * from './AcquiredItem'; +export * from './acquisition'; + +export { default as AcquisitionResultTable } from './AcquisitionResultTable.vue'; +export { default as BuyModal } from './BuyModal.vue'; +export { default as SellModal } from './SellModal.vue'; + diff --git a/src/market/track/TrackedItem.ts b/src/market/track/TrackedItem.ts deleted file mode 100644 index 77a0289..0000000 --- a/src/market/track/TrackedItem.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { MarketType } from "@/market"; - -export type TrackedItem = { - type: MarketType; - count: number; - averagePrice: number; - buy: number, - sell: number -} \ No newline at end of file diff --git a/src/market/track/index.ts b/src/market/track/index.ts deleted file mode 100644 index 7c25866..0000000 --- a/src/market/track/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './TrackedItem'; -export * from './track'; - -export { default as BuyModal } from './BuyModal.vue'; -export { default as SellModal } from './SellModal.vue'; -export { default as TrackResultTable } from './TrackResultTable.vue'; - diff --git a/src/market/track/track.ts b/src/market/track/track.ts deleted file mode 100644 index f8b2c7d..0000000 --- a/src/market/track/track.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { useCollection, usePocketBase } from "@/pocketbase"; -import { createSharedComposable, useLocalStorage } from '@vueuse/core'; -import { defineStore } from "pinia"; -import { RecordModel } from "pocketbase"; -import { computed } from "vue"; - -export type TrackedMarketItemStorage = { - typeID: number; - count: number; - averagePrice: number; -} - -interface TrackedMarketItem extends RecordModel { - owner: string; - typeID: number; - count: number; - averagePrice: number; -} - -const marketTrackings = 'marketTrackings'; - -export const useTrackedItemsStorage = createSharedComposable(() => useLocalStorage('market-track-items', [])); - -export const useTrackedItemStore = defineStore(marketTrackings, () => { - const pb = usePocketBase(); - const trackedItems = useCollection(marketTrackings); - - const items = computed(() => trackedItems); - const addTrackedItem = async (typeID: number, count: number, averagePrice: number) => { - const oldItem = trackedItems.value.find(i => i.typeID === typeID); - - if (oldItem?.id) { - pb.collection(marketTrackings).update(oldItem.id, { - ...oldItem, - count: count + oldItem.count, - averagePrice: ((averagePrice * count) + (oldItem.averagePrice * oldItem.count)) / (count + oldItem.count) - }); - } else { - pb.collection(marketTrackings).create({ owner: pb.authStore.model!.id, typeID, count, averagePrice}); - } - }; - const removeTrackedItem = async (typeID: number, count: number) => { - const oldItem = trackedItems.value.find(i => i.typeID === typeID); - - if (!oldItem?.id) { - return; - } else if (oldItem.count > count) { - pb.collection(marketTrackings).update(oldItem.id, { - ...oldItem, - count: oldItem.count - count - }); - } else { - pb.collection(marketTrackings).delete(oldItem.id); - } - }; - - return { items, addTrackedItem, removeTrackedItem }; -}); \ No newline at end of file diff --git a/src/pages/Market.vue b/src/pages/Market.vue index f382238..46170d6 100644 --- a/src/pages/Market.vue +++ b/src/pages/Market.vue @@ -12,8 +12,8 @@ import { RouterLink, RouterView } from 'vue-router'; Scan - - Tracking + + Acquisitions diff --git a/src/pages/market/Acquisitions.vue b/src/pages/market/Acquisitions.vue new file mode 100644 index 0000000..1b309b0 --- /dev/null +++ b/src/pages/market/Acquisitions.vue @@ -0,0 +1,43 @@ + + +@/market/acquisition \ No newline at end of file diff --git a/src/pages/market/Scan.vue b/src/pages/market/Scan.vue index 5398b3f..2c5e2fb 100644 --- a/src/pages/market/Scan.vue +++ b/src/pages/market/Scan.vue @@ -1,7 +1,7 @@ - - \ No newline at end of file diff --git a/src/routes.ts b/src/routes.ts index 02f7a54..4e45d16 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -8,7 +8,7 @@ export const routes: RouteRecordRaw[] = [ { path: '', redirect: '/market/type' }, { path: 'type/:type?', name: 'market-type', component: () => import('@/pages/market/TypeInfo.vue') }, { path: 'scan', component: () => import('@/pages/market/Scan.vue') }, - { path: 'track', component: () => import('@/pages/market/Track.vue') }, + { path: 'acquisitions', component: () => import('@/pages/market/Acquisitions.vue') }, ] }, { path: '/tools', component: () => import('@/pages/Tools.vue') }, { path: '/about', component: () => import('@/pages/About.vue') },