Fix marbas integration
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { MarketType } from "..";
|
||||
import { AcquiredMarketType } from "./acquisition";
|
||||
import { MarbasAcquiredType } from "./acquisition";
|
||||
|
||||
export type AcquiredType = Omit<AcquiredMarketType, 'type'> & {
|
||||
export type AcquiredType = Omit<MarbasAcquiredType, 'type'> & {
|
||||
type: MarketType,
|
||||
buy: number,
|
||||
sell: number
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { SortableHeader, useSort } from '@/components/table';
|
||||
import { formatIsk, percentFormater } from '@/formaters';
|
||||
import { MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/market";
|
||||
import { MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/market";
|
||||
import { MinusIcon, PlusIcon } from '@heroicons/vue/24/outline';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { computed, ref } from 'vue';
|
||||
@@ -9,7 +9,7 @@ import { AcquiredType } from './AcquiredType';
|
||||
import AcquisitionQuantilsTooltip from './AcquisitionQuantilsTooltip.vue';
|
||||
|
||||
type Result = {
|
||||
type: MarketType;
|
||||
type: AcquiredType;
|
||||
typeID: number;
|
||||
name: string;
|
||||
buy: number;
|
||||
@@ -26,8 +26,8 @@ interface Props {
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'buy', type: MarketType, price: number, buy: number, sell: number): void;
|
||||
(e: 'sell', type: MarketType): void;
|
||||
(e: 'buy', type: AcquiredType, price: number, buy: number, sell: number): void;
|
||||
(e: 'sell', type: AcquiredType): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -46,7 +46,7 @@ const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items
|
||||
const precentProfit = marketTaxStore.calculateProfit(r.price, r.sell);
|
||||
|
||||
return {
|
||||
type: r.type,
|
||||
type: r,
|
||||
typeID: r.type.id,
|
||||
name: r.type.name,
|
||||
buy: r.buy,
|
||||
|
||||
@@ -38,7 +38,7 @@ const add = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
acquiredTypesStore.addType(id, count.value, price.value);
|
||||
acquiredTypesStore.addAcquiredType(id, count.value, price.value);
|
||||
modalOpen.value = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { Modal } from '@/components';
|
||||
import { MarketType, MarketTypeLabel } from '@/market';
|
||||
import { ref } from 'vue';
|
||||
import { AcquiredType } from './AcquiredType';
|
||||
import { useAcquiredTypesStore } from './acquisition';
|
||||
|
||||
|
||||
@@ -10,21 +11,21 @@ const acquiredTypesStore = useAcquiredTypesStore();
|
||||
const modalOpen = ref<boolean>(false);
|
||||
const type = ref<MarketType>();
|
||||
const count = ref(1);
|
||||
const id = ref<number>();
|
||||
|
||||
const open = (t: MarketType) => {
|
||||
type.value = t;
|
||||
const open = (t: AcquiredType) => {
|
||||
id.value = t.id;
|
||||
type.value = t.type;
|
||||
count.value = 1;
|
||||
modalOpen.value = true;
|
||||
}
|
||||
const remove = () => {
|
||||
const id = type.value?.id;
|
||||
|
||||
if (!id) {
|
||||
if (!id.value) {
|
||||
modalOpen.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
acquiredTypesStore.removeType(id, count.value);
|
||||
acquiredTypesStore.removeAcquiredType(id.value, count.value);
|
||||
modalOpen.value = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,41 @@
|
||||
import { marbasAxiosInstance } from "@/service";
|
||||
import { marbasAxiosInstance, MarbasObject } from "@/marbas";
|
||||
import log from "loglevel";
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
export type AcquiredMarketType = {
|
||||
id: number;
|
||||
export type AcquiredTypeSource = 'bo' | 'so' | 'prod';
|
||||
|
||||
export type MarbasAcquiredType = MarbasObject & {
|
||||
type: number;
|
||||
quantity: number;
|
||||
remaining: number;
|
||||
price: number;
|
||||
date: Date;
|
||||
source: 'bo' | 'so' | 'prod';
|
||||
source: AcquiredTypeSource;
|
||||
user: number;
|
||||
}
|
||||
|
||||
const endpoint = '/api/acquisitions/';
|
||||
|
||||
export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
||||
const acquiredTypes = ref<AcquiredMarketType[]>([]);
|
||||
const acquiredTypes = ref<MarbasAcquiredType[]>([]);
|
||||
|
||||
const types = computed(() => acquiredTypes.value.filter(item => item.remaining > 0));
|
||||
const addType = async (type: number, quantity: number, price: number) => {
|
||||
acquiredTypes.value = [...acquiredTypes.value, (await marbasAxiosInstance.post<AcquiredMarketType>(endpoint, {
|
||||
const addAcquiredType = async (type: number, quantity: number, price: number, source?: AcquiredTypeSource) => {
|
||||
const newItem = (await marbasAxiosInstance.post<MarbasAcquiredType>(endpoint, {
|
||||
type: type,
|
||||
quantity: quantity,
|
||||
remaining: quantity,
|
||||
price: price,
|
||||
date: new Date(),
|
||||
source: 'bo'
|
||||
})).data];
|
||||
source: source ?? 'bo',
|
||||
})).data
|
||||
|
||||
acquiredTypes.value = [...acquiredTypes.value, newItem];
|
||||
log.info(`Acquired type ${newItem.id} with quantity ${newItem.quantity} and price ${newItem.price}`, newItem);
|
||||
};
|
||||
const removeType = async (type: number, quantity: number) => {
|
||||
const found = acquiredTypes.value.find(item => item.type === type);
|
||||
const removeAcquiredType = async (id: number, quantity: number) => {
|
||||
const found = acquiredTypes.value.find(t => t.id === id);
|
||||
|
||||
if (!found) {
|
||||
return;
|
||||
@@ -41,21 +46,18 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
||||
remaining: Math.max(0, found.remaining - quantity)
|
||||
};
|
||||
|
||||
if (found.remaining <= 0) {
|
||||
acquiredTypes.value = acquiredTypes.value.filter(i => i.type !== type);
|
||||
} else {
|
||||
acquiredTypes.value = acquiredTypes.value.map(i => {
|
||||
if (i.type === item.type) {
|
||||
return item;
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
});
|
||||
}
|
||||
acquiredTypes.value = acquiredTypes.value.map(i => {
|
||||
if (i.id === item.id) {
|
||||
return item;
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
});
|
||||
await marbasAxiosInstance.put(`${endpoint}${item.id}/`, item);
|
||||
log.info(`Acquired type ${item.id} remaining: ${item.remaining}`, item);
|
||||
};
|
||||
|
||||
marbasAxiosInstance.get<AcquiredMarketType[]>(endpoint).then(res => acquiredTypes.value = res.data);
|
||||
marbasAxiosInstance.get<MarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data);
|
||||
|
||||
return { types, addType, removeType };
|
||||
return { acquiredTypes: types, addAcquiredType, removeAcquiredType };
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { MarketOrderHistory, MarketType, MarketTypePrice, getHistory, jitaId } from "@/market";
|
||||
import { marbasAxiosInstance } from "@/service";
|
||||
import { marbasAxiosInstance, MarbasObject } from "@/marbas";
|
||||
import { getHistory, jitaId, MarketOrderHistory, MarketType, MarketTypePrice } from "@/market";
|
||||
import log from "loglevel";
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
@@ -11,22 +12,22 @@ export type TrackingResult = {
|
||||
orderCount: number,
|
||||
}
|
||||
|
||||
type MarketTracking = {
|
||||
id: number,
|
||||
export type MarbasTrackedType = MarbasObject & {
|
||||
type: number
|
||||
};
|
||||
|
||||
const endpoint = '/api/types_tracking/';
|
||||
|
||||
export const useMarketTrackingStore = defineStore('marketTracking', () => {
|
||||
const trackedTypes = ref<MarketTracking[]>([]);
|
||||
const trackedTypes = ref<MarbasTrackedType[]>([]);
|
||||
|
||||
const types = computed(() => trackedTypes.value.map(item => item.type) ?? []);
|
||||
const addType = async (type: number) => {
|
||||
const found = trackedTypes.value.find(item => item.type === type);
|
||||
|
||||
if (!found) {
|
||||
trackedTypes.value = [...trackedTypes.value, (await marbasAxiosInstance.post<MarketTracking>(endpoint, { type })).data];
|
||||
trackedTypes.value = [...trackedTypes.value, (await marbasAxiosInstance.post<MarbasTrackedType>(endpoint, { type })).data];
|
||||
log.info(`Tracking type ${type}`);
|
||||
}
|
||||
}
|
||||
const removeType = async (type: number) => {
|
||||
@@ -38,9 +39,10 @@ export const useMarketTrackingStore = defineStore('marketTracking', () => {
|
||||
|
||||
trackedTypes.value = trackedTypes.value.filter(t => t.id !== found.id);
|
||||
await marbasAxiosInstance.delete(`${endpoint}${found.id}`);
|
||||
log.info(`Stopped tracking type ${type}`);
|
||||
}
|
||||
|
||||
marbasAxiosInstance.get<MarketTracking[]>(endpoint).then(res => trackedTypes.value = res.data);
|
||||
marbasAxiosInstance.get<MarbasTrackedType[]>(endpoint).then(res => trackedTypes.value = res.data);
|
||||
|
||||
return { types, addType, removeType };
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { marbasAxiosInstance } from "@/service";
|
||||
import { marbasAxiosInstance } from "@/marbas";
|
||||
|
||||
export type MarketType = {
|
||||
id: number;
|
||||
|
||||
Reference in New Issue
Block a user