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