Rework to use marbas and authentik instead of poketbase (#1)

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2024-05-17 23:00:52 +02:00
parent 9fb78329cc
commit 717eaa6ed8
47 changed files with 2306 additions and 1049 deletions

View File

@@ -0,0 +1,63 @@
import { marbasAxiosInstance } from "@/service";
import { defineStore } from "pinia";
import { computed, ref } from "vue";
export type AcquiredMarketType = {
id: number;
type: number;
quantity: number;
remaining: number;
price: number;
date: Date;
source: 'bo' | 'so' | 'prod';
user: number;
}
const endpoint = '/api/acquisitions/';
export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
const acquiredTypes = ref<AcquiredMarketType[]>([]);
const types = computed(() => acquiredTypes.value);
const addType = async (type: number, quantity: number, price: number) => {
acquiredTypes.value = [...acquiredTypes.value, (await marbasAxiosInstance.post<AcquiredMarketType>(endpoint, {
type: type,
quantity: quantity,
remaining: quantity,
price: price,
date: new Date(),
source: 'bo'
})).data];
};
const removeType = async (type: number, quantity: number) => {
const found = acquiredTypes.value.find(item => item.type === type);
if (!found) {
return;
}
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;
}
});
}
const item = {
...found,
remaining: found.remaining - quantity
};
await marbasAxiosInstance.put(`${endpoint}${item.id}`, item);
};
marbasAxiosInstance.get<AcquiredMarketType[]>(endpoint).then(res => acquiredTypes.value = res.data.filter(item => item.remaining > 0));
return { types, addType, removeType };
});