Fix tracking id
This commit is contained in:
@@ -19,21 +19,28 @@ type MarketTracking = {
|
||||
const endpoint = '/api/types_tracking/';
|
||||
|
||||
export const useMarketTrackingStore = defineStore('marketTracking', () => {
|
||||
const trackedTypes = ref<number[]>([]);
|
||||
const trackedTypes = ref<MarketTracking[]>([]);
|
||||
|
||||
const types = computed(() => trackedTypes.value ?? []);
|
||||
const types = computed(() => trackedTypes.value.map(item => item.type) ?? []);
|
||||
const addType = async (type: number) => {
|
||||
if (!trackedTypes.value.includes(type)) {
|
||||
await marbasAxiosInstance.post(endpoint, { type });
|
||||
const found = trackedTypes.value.find(item => item.type === type);
|
||||
|
||||
if (!found) {
|
||||
trackedTypes.value = [...trackedTypes.value, (await marbasAxiosInstance.post<MarketTracking>(endpoint, { type })).data];
|
||||
}
|
||||
}
|
||||
const removeType = async (type: number) => {
|
||||
if (trackedTypes.value.includes(type)) {
|
||||
await marbasAxiosInstance.delete(`${endpoint}${type}`);
|
||||
const found = trackedTypes.value.find(item => item.type === type);
|
||||
|
||||
if (!found) {
|
||||
return;
|
||||
}
|
||||
|
||||
trackedTypes.value = trackedTypes.value.filter(t => t.id !== found.id);
|
||||
await marbasAxiosInstance.delete(`${endpoint}${found.id}`);
|
||||
}
|
||||
|
||||
marbasAxiosInstance.get<MarketTracking[]>(endpoint).then(res => trackedTypes.value = res.data.map(item => item.type));
|
||||
marbasAxiosInstance.get<MarketTracking[]>(endpoint).then(res => trackedTypes.value = res.data);
|
||||
|
||||
return { types, addType, removeType };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user