Compare commits

...

2 Commits

Author SHA1 Message Date
4748b15cc4 cleanup formater 2024-05-27 12:16:50 +02:00
9ccba70ede fix acquisition creeation 2024-05-27 12:16:15 +02:00
2 changed files with 16 additions and 11 deletions

View File

@@ -18,10 +18,4 @@ const timeFormat = new Intl.NumberFormat("en-US", {
minimumIntegerDigits: 2 minimumIntegerDigits: 2
}); });
export const formatEveDate = (date?: Date | null) => { export const formatEveDate = (date?: Date | null) => !date ? '' : `${date.getUTCFullYear()}.${timeFormat.format(date.getUTCMonth() + 1)}.${timeFormat.format(date.getUTCDate())} ${timeFormat.format(date.getUTCHours())}:${timeFormat.format(date.getUTCMinutes())}`;
try {
return !date ? '' : `${date.getUTCFullYear()}.${timeFormat.format(date.getUTCMonth() + 1)}.${timeFormat.format(date.getUTCDate())} ${timeFormat.format(date.getUTCHours())}:${timeFormat.format(date.getUTCMinutes())}`;
} catch (e) {
return '';
}
};

View File

@@ -1,4 +1,5 @@
import { marbasAxiosInstance, MarbasObject } from "@/marbas"; import { marbasAxiosInstance, MarbasObject } from "@/marbas";
import { AxiosResponse } from "axios";
import log from "loglevel"; import log from "loglevel";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { computed, ref } from "vue"; import { computed, ref } from "vue";
@@ -15,6 +16,17 @@ export type MarbasAcquiredType = MarbasObject & {
user: number; user: number;
} }
type RawMarbasAcquiredType = Omit<MarbasAcquiredType, 'date'> & {
date: string;
}
type InsertableRawMarbasAcquiredType = Omit<MarbasAcquiredType, 'id' | 'user' | 'date'>;
const mapRawMarbasAcquiredType = (raw: RawMarbasAcquiredType): MarbasAcquiredType => ({
...raw,
date: raw.date ? new Date(raw.date) : new Date()
});
const endpoint = '/api/acquisitions/'; const endpoint = '/api/acquisitions/';
export const useAcquiredTypesStore = defineStore('market-acquisition', () => { export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
@@ -22,14 +34,13 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
const types = computed(() => acquiredTypes.value.filter(item => item.remaining > 0)); const types = computed(() => acquiredTypes.value.filter(item => item.remaining > 0));
const addAcquiredType = async (type: number, quantity: number, price: number, source?: AcquiredTypeSource) => { const addAcquiredType = async (type: number, quantity: number, price: number, source?: AcquiredTypeSource) => {
const newItem = (await marbasAxiosInstance.post<MarbasAcquiredType>(endpoint, { const newItem = mapRawMarbasAcquiredType((await marbasAxiosInstance.post<RawMarbasAcquiredType, AxiosResponse<RawMarbasAcquiredType>, InsertableRawMarbasAcquiredType>(endpoint, {
type: type, type: type,
quantity: quantity, quantity: quantity,
remaining: quantity, remaining: quantity,
price: price, price: price,
date: new Date(),
source: source ?? 'misc', source: source ?? 'misc',
})).data })).data);
acquiredTypes.value = [...acquiredTypes.value, newItem]; acquiredTypes.value = [...acquiredTypes.value, newItem];
log.info(`Acquired type ${newItem.id} with quantity ${newItem.quantity} and price ${newItem.price}`, newItem); log.info(`Acquired type ${newItem.id} with quantity ${newItem.quantity} and price ${newItem.price}`, newItem);
@@ -57,7 +68,7 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
log.info(`Acquired type ${item.id} remaining: ${item.remaining}`, item); log.info(`Acquired type ${item.id} remaining: ${item.remaining}`, item);
}; };
marbasAxiosInstance.get<MarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data.map(item => ({ ...item, date: new Date(item.date) }))); marbasAxiosInstance.get<RawMarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data.map(mapRawMarbasAcquiredType));
return { acquiredTypes: types, addAcquiredType, removeAcquiredType }; return { acquiredTypes: types, addAcquiredType, removeAcquiredType };
}); });