Fix marbas integration
This commit is contained in:
3
src/marbas/MarbasObject.ts
Normal file
3
src/marbas/MarbasObject.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export type MarbasObject = {
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
3
src/marbas/index.ts
Normal file
3
src/marbas/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export * from './MarbasObject';
|
||||||
|
export * from './marbasService';
|
||||||
|
|
||||||
46
src/marbas/marbasService.ts
Normal file
46
src/marbas/marbasService.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { useAuthStore } from "@/auth";
|
||||||
|
import { logResource } from "@/service";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export const marbasAxiosInstance = axios.create({
|
||||||
|
baseURL: import.meta.env.VITE_MARBAS_URL,
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
marbasAxiosInstance.interceptors.request.use(r => {
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
|
if (!authStore.isLoggedIn) {
|
||||||
|
throw new Error("Not logged in");
|
||||||
|
}
|
||||||
|
|
||||||
|
const accessToken = authStore.accessToken;
|
||||||
|
|
||||||
|
if (accessToken) {
|
||||||
|
r.headers.Authorization = `Bearer ${accessToken}`;
|
||||||
|
}
|
||||||
|
if (!r.params?.page_size) {
|
||||||
|
r.params = { ...r.params, page_size: 250 };
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
})
|
||||||
|
logResource(marbasAxiosInstance)
|
||||||
|
marbasAxiosInstance.interceptors.response.use(async r => {
|
||||||
|
const next = r.data?.next;
|
||||||
|
let results = r.data?.results;
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
results = results.concat((await marbasAxiosInstance.request({
|
||||||
|
...r.config,
|
||||||
|
url: next,
|
||||||
|
baseURL: '',
|
||||||
|
})).data);
|
||||||
|
}
|
||||||
|
if (results) {
|
||||||
|
r.data = results;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
})
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { MarketType } from "..";
|
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,
|
type: MarketType,
|
||||||
buy: number,
|
buy: number,
|
||||||
sell: number
|
sell: number
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { SortableHeader, useSort } from '@/components/table';
|
import { SortableHeader, useSort } from '@/components/table';
|
||||||
import { formatIsk, percentFormater } from '@/formaters';
|
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 { MinusIcon, PlusIcon } from '@heroicons/vue/24/outline';
|
||||||
import { useStorage } from '@vueuse/core';
|
import { useStorage } from '@vueuse/core';
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
@@ -9,7 +9,7 @@ import { AcquiredType } from './AcquiredType';
|
|||||||
import AcquisitionQuantilsTooltip from './AcquisitionQuantilsTooltip.vue';
|
import AcquisitionQuantilsTooltip from './AcquisitionQuantilsTooltip.vue';
|
||||||
|
|
||||||
type Result = {
|
type Result = {
|
||||||
type: MarketType;
|
type: AcquiredType;
|
||||||
typeID: number;
|
typeID: number;
|
||||||
name: string;
|
name: string;
|
||||||
buy: number;
|
buy: number;
|
||||||
@@ -26,8 +26,8 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Emits {
|
interface Emits {
|
||||||
(e: 'buy', type: MarketType, price: number, buy: number, sell: number): void;
|
(e: 'buy', type: AcquiredType, price: number, buy: number, sell: number): void;
|
||||||
(e: 'sell', type: MarketType): void;
|
(e: 'sell', type: AcquiredType): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
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);
|
const precentProfit = marketTaxStore.calculateProfit(r.price, r.sell);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: r.type,
|
type: r,
|
||||||
typeID: r.type.id,
|
typeID: r.type.id,
|
||||||
name: r.type.name,
|
name: r.type.name,
|
||||||
buy: r.buy,
|
buy: r.buy,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const add = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
acquiredTypesStore.addType(id, count.value, price.value);
|
acquiredTypesStore.addAcquiredType(id, count.value, price.value);
|
||||||
modalOpen.value = false;
|
modalOpen.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { Modal } from '@/components';
|
import { Modal } from '@/components';
|
||||||
import { MarketType, MarketTypeLabel } from '@/market';
|
import { MarketType, MarketTypeLabel } from '@/market';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
import { AcquiredType } from './AcquiredType';
|
||||||
import { useAcquiredTypesStore } from './acquisition';
|
import { useAcquiredTypesStore } from './acquisition';
|
||||||
|
|
||||||
|
|
||||||
@@ -10,21 +11,21 @@ const acquiredTypesStore = useAcquiredTypesStore();
|
|||||||
const modalOpen = ref<boolean>(false);
|
const modalOpen = ref<boolean>(false);
|
||||||
const type = ref<MarketType>();
|
const type = ref<MarketType>();
|
||||||
const count = ref(1);
|
const count = ref(1);
|
||||||
|
const id = ref<number>();
|
||||||
|
|
||||||
const open = (t: MarketType) => {
|
const open = (t: AcquiredType) => {
|
||||||
type.value = t;
|
id.value = t.id;
|
||||||
|
type.value = t.type;
|
||||||
count.value = 1;
|
count.value = 1;
|
||||||
modalOpen.value = true;
|
modalOpen.value = true;
|
||||||
}
|
}
|
||||||
const remove = () => {
|
const remove = () => {
|
||||||
const id = type.value?.id;
|
if (!id.value) {
|
||||||
|
|
||||||
if (!id) {
|
|
||||||
modalOpen.value = false;
|
modalOpen.value = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
acquiredTypesStore.removeType(id, count.value);
|
acquiredTypesStore.removeAcquiredType(id.value, count.value);
|
||||||
modalOpen.value = false;
|
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 { defineStore } from "pinia";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
|
|
||||||
export type AcquiredMarketType = {
|
export type AcquiredTypeSource = 'bo' | 'so' | 'prod';
|
||||||
id: number;
|
|
||||||
|
export type MarbasAcquiredType = MarbasObject & {
|
||||||
type: number;
|
type: number;
|
||||||
quantity: number;
|
quantity: number;
|
||||||
remaining: number;
|
remaining: number;
|
||||||
price: number;
|
price: number;
|
||||||
date: Date;
|
date: Date;
|
||||||
source: 'bo' | 'so' | 'prod';
|
source: AcquiredTypeSource;
|
||||||
user: number;
|
user: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const endpoint = '/api/acquisitions/';
|
const endpoint = '/api/acquisitions/';
|
||||||
|
|
||||||
export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
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 types = computed(() => acquiredTypes.value.filter(item => item.remaining > 0));
|
||||||
const addType = async (type: number, quantity: number, price: number) => {
|
const addAcquiredType = async (type: number, quantity: number, price: number, source?: AcquiredTypeSource) => {
|
||||||
acquiredTypes.value = [...acquiredTypes.value, (await marbasAxiosInstance.post<AcquiredMarketType>(endpoint, {
|
const newItem = (await marbasAxiosInstance.post<MarbasAcquiredType>(endpoint, {
|
||||||
type: type,
|
type: type,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
remaining: quantity,
|
remaining: quantity,
|
||||||
price: price,
|
price: price,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
source: 'bo'
|
source: source ?? 'bo',
|
||||||
})).data];
|
})).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 removeAcquiredType = async (id: number, quantity: number) => {
|
||||||
const found = acquiredTypes.value.find(item => item.type === type);
|
const found = acquiredTypes.value.find(t => t.id === id);
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
return;
|
return;
|
||||||
@@ -41,21 +46,18 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
|||||||
remaining: Math.max(0, found.remaining - quantity)
|
remaining: Math.max(0, found.remaining - quantity)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (found.remaining <= 0) {
|
acquiredTypes.value = acquiredTypes.value.map(i => {
|
||||||
acquiredTypes.value = acquiredTypes.value.filter(i => i.type !== type);
|
if (i.id === item.id) {
|
||||||
} else {
|
return item;
|
||||||
acquiredTypes.value = acquiredTypes.value.map(i => {
|
} else {
|
||||||
if (i.type === item.type) {
|
return i;
|
||||||
return item;
|
}
|
||||||
} else {
|
});
|
||||||
return i;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
await marbasAxiosInstance.put(`${endpoint}${item.id}/`, item);
|
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, MarbasObject } from "@/marbas";
|
||||||
import { marbasAxiosInstance } from "@/service";
|
import { getHistory, jitaId, MarketOrderHistory, MarketType, MarketTypePrice } from "@/market";
|
||||||
|
import log from "loglevel";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
|
|
||||||
@@ -11,22 +12,22 @@ export type TrackingResult = {
|
|||||||
orderCount: number,
|
orderCount: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
type MarketTracking = {
|
export type MarbasTrackedType = MarbasObject & {
|
||||||
id: number,
|
|
||||||
type: number
|
type: number
|
||||||
};
|
};
|
||||||
|
|
||||||
const endpoint = '/api/types_tracking/';
|
const endpoint = '/api/types_tracking/';
|
||||||
|
|
||||||
export const useMarketTrackingStore = defineStore('marketTracking', () => {
|
export const useMarketTrackingStore = defineStore('marketTracking', () => {
|
||||||
const trackedTypes = ref<MarketTracking[]>([]);
|
const trackedTypes = ref<MarbasTrackedType[]>([]);
|
||||||
|
|
||||||
const types = computed(() => trackedTypes.value.map(item => item.type) ?? []);
|
const types = computed(() => trackedTypes.value.map(item => item.type) ?? []);
|
||||||
const addType = async (type: number) => {
|
const addType = async (type: number) => {
|
||||||
const found = trackedTypes.value.find(item => item.type === type);
|
const found = trackedTypes.value.find(item => item.type === type);
|
||||||
|
|
||||||
if (!found) {
|
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) => {
|
const removeType = async (type: number) => {
|
||||||
@@ -38,9 +39,10 @@ export const useMarketTrackingStore = defineStore('marketTracking', () => {
|
|||||||
|
|
||||||
trackedTypes.value = trackedTypes.value.filter(t => t.id !== found.id);
|
trackedTypes.value = trackedTypes.value.filter(t => t.id !== found.id);
|
||||||
await marbasAxiosInstance.delete(`${endpoint}${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 };
|
return { types, addType, removeType };
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { marbasAxiosInstance } from "@/service";
|
import { marbasAxiosInstance } from "@/marbas";
|
||||||
|
|
||||||
export type MarketType = {
|
export type MarketType = {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const apraisalStore = useApraisalStore();
|
|||||||
const acquiredTypesStore = useAcquiredTypesStore();
|
const acquiredTypesStore = useAcquiredTypesStore();
|
||||||
const items = ref<AcquiredType[]>([]);
|
const items = ref<AcquiredType[]>([]);
|
||||||
|
|
||||||
watch(() => acquiredTypesStore.types, async itms => {
|
watch(() => acquiredTypesStore.acquiredTypes, async itms => {
|
||||||
if (itms.length === 0) {
|
if (itms.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ watch(() => acquiredTypesStore.types, async itms => {
|
|||||||
<template>
|
<template>
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<template v-if="items.length > 0">
|
<template v-if="items.length > 0">
|
||||||
<AcquisitionResultTable :items="items" @buy="(type, price, buy, sell) => buyModal?.open(type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="type => sellModal?.open(type)" />
|
<AcquisitionResultTable :items="items" @buy="(type, price, buy, sell) => buyModal?.open(type.type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="type => sellModal?.open(type)" />
|
||||||
<BuyModal ref="buyModal" />
|
<BuyModal ref="buyModal" />
|
||||||
<SellModal ref="sellModal" />
|
<SellModal ref="sellModal" />
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const isTracked = computed(() => item.value ? marketTrackingStore.types.includes
|
|||||||
const acquisitions = computed(() => {
|
const acquisitions = computed(() => {
|
||||||
const p = price.value;
|
const p = price.value;
|
||||||
|
|
||||||
return !p ?[] : acquiredTypesStore.types
|
return !p ?[] : acquiredTypesStore.acquiredTypes
|
||||||
.filter(t => t.type === item.value?.id)
|
.filter(t => t.type === item.value?.id)
|
||||||
.map(i => ({
|
.map(i => ({
|
||||||
...i,
|
...i,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { marbasAxiosInstance } from "@/service";
|
import { marbasAxiosInstance } from "@/marbas";
|
||||||
|
|
||||||
export type ReprocessItemValues = {
|
export type ReprocessItemValues = {
|
||||||
typeID: number;
|
typeID: number;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { useAuthStore } from '@/auth';
|
|
||||||
import axios, { AxiosInstance } from 'axios';
|
import axios, { AxiosInstance } from 'axios';
|
||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
|
|
||||||
@@ -15,48 +14,6 @@ export const logResource = (a: AxiosInstance) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const marbasAxiosInstance = axios.create({
|
|
||||||
baseURL: import.meta.env.VITE_MARBAS_URL,
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
marbasAxiosInstance.interceptors.request.use(r => {
|
|
||||||
const authStore = useAuthStore();
|
|
||||||
|
|
||||||
if (!authStore.isLoggedIn) {
|
|
||||||
throw new Error("Not logged in");
|
|
||||||
}
|
|
||||||
|
|
||||||
const accessToken = authStore.accessToken;
|
|
||||||
|
|
||||||
if (accessToken) {
|
|
||||||
r.headers.Authorization = `Bearer ${accessToken}`;
|
|
||||||
}
|
|
||||||
if (!r.params?.page_size) {
|
|
||||||
r.params = { ...r.params, page_size: 250 };
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
})
|
|
||||||
logResource(marbasAxiosInstance)
|
|
||||||
marbasAxiosInstance.interceptors.response.use(async r => {
|
|
||||||
const next = r.data?.next;
|
|
||||||
let results = r.data?.results;
|
|
||||||
|
|
||||||
if (next) {
|
|
||||||
results = results.concat((await marbasAxiosInstance.request({
|
|
||||||
...r.config,
|
|
||||||
url: next,
|
|
||||||
baseURL: '',
|
|
||||||
})).data);
|
|
||||||
}
|
|
||||||
if (results) {
|
|
||||||
r.data = results;
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
})
|
|
||||||
|
|
||||||
export const esiAxiosInstance = axios.create({
|
export const esiAxiosInstance = axios.create({
|
||||||
baseURL: import.meta.env.VITE_ESI_URL,
|
baseURL: import.meta.env.VITE_ESI_URL,
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
Reference in New Issue
Block a user