feat(#14): Wire manual buy/sell to the mammon acquire/consume endpoints
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {computed, ref} from "vue";
|
||||
import {acquisitionApi} from "@/mammon";
|
||||
import {acquisitionApi, activityApi} from "@/mammon";
|
||||
import {AcquisitionResponse, ActivitySourceResponse} from "@/generated/mammon";
|
||||
|
||||
export type AcquiredTypeSource = 'bo' | 'so' | 'prod' | 'misc';
|
||||
|
||||
export type RawAcquiredType = {
|
||||
id: string;
|
||||
ledgerId: string;
|
||||
@@ -32,14 +30,41 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
||||
|
||||
const types = computed(() => acquiredTypes.value.filter(item => item.remaining > 0));
|
||||
|
||||
// Display-only: the backend exposes no write endpoint yet, so buy/sell are no-ops.
|
||||
const addAcquiredType = async (_type: number, _quantity: number, _price: number, _source?: AcquiredTypeSource) => {};
|
||||
const removeAcquiredType = async (_id: string, _quantity: number) => {};
|
||||
const addAcquiredType = (type: number, quantity: number, price: number, ledgerId: string, datetime: Date) =>
|
||||
activityApi.acquire({
|
||||
source: { type: 'LEDGER', characterId: null, ledgerId },
|
||||
marketTypeId: type,
|
||||
quantity,
|
||||
unitPrice: price,
|
||||
datetime: datetime.toISOString(),
|
||||
taxes: null,
|
||||
description: null,
|
||||
});
|
||||
|
||||
const removeAcquiredType = (id: string, quantity: number, ledgerId: string, datetime: Date) => {
|
||||
const acquisition = acquiredTypes.value.find(a => a.id === id);
|
||||
|
||||
if (!acquisition) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return activityApi.consume({
|
||||
source: { type: 'LEDGER', characterId: null, ledgerId },
|
||||
marketTypeId: acquisition.type,
|
||||
quantity,
|
||||
unitPrice: 0,
|
||||
datetime: datetime.toISOString(),
|
||||
taxes: null,
|
||||
description: null,
|
||||
});
|
||||
};
|
||||
|
||||
const processNewActivities = () => activityApi.processNewActivities();
|
||||
|
||||
const refresh = () => acquisitionApi.findAllAcquisitions()
|
||||
.then(response => acquiredTypes.value = response.data.map(toAcquiredType));
|
||||
|
||||
refresh();
|
||||
|
||||
return { acquiredTypes: types, addAcquiredType, removeAcquiredType, refresh };
|
||||
return { acquiredTypes: types, addAcquiredType, removeAcquiredType, processNewActivities, refresh };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user