33 lines
875 B
TypeScript
33 lines
875 B
TypeScript
import { defineStore } from 'pinia';
|
|
import { useAccessToken } from '../composables/useAccessToken';
|
|
import { BACKEND_URL } from '../constants';
|
|
import { StoredItem } from '../interfaces/storage.interfaces';
|
|
import jfetch from '../utils/jfetch';
|
|
|
|
const { authHeader } = useAccessToken();
|
|
export const useStorageStore = defineStore('storage', {
|
|
state: () => {
|
|
return {
|
|
loadingExpiringItems: false,
|
|
expiringItems: [] as StoredItem[],
|
|
};
|
|
},
|
|
actions: {
|
|
async getExpiringItems() {
|
|
this.loadingExpiringItems = true;
|
|
this.expiringItems = [];
|
|
try {
|
|
const { data: items } = await jfetch(
|
|
`${BACKEND_URL}/storage/expiring`,
|
|
{
|
|
headers: authHeader.value,
|
|
}
|
|
);
|
|
this.expiringItems = items;
|
|
} finally {
|
|
this.loadingExpiringItems = false;
|
|
}
|
|
},
|
|
},
|
|
});
|