forked from mirrors/homebox
feat: group statistics endpoint (#123)
* group statistics endpoint * remove item store * return possible errors * add statistics tests
This commit is contained in:
parent
a886fa86ca
commit
7e0f1fac23
13 changed files with 201 additions and 74 deletions
|
@ -1,33 +0,0 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ItemOut } from "~~/lib/api/types/data-contracts";
|
||||
|
||||
export const useItemStore = defineStore("items", {
|
||||
state: () => ({
|
||||
allItems: null as ItemOut[] | null,
|
||||
client: useUserApi(),
|
||||
}),
|
||||
getters: {
|
||||
/**
|
||||
* items represents the items that are currently in the store. The store is
|
||||
* synched with the server by intercepting the API calls and updating on the
|
||||
* response.
|
||||
*/
|
||||
items(state): ItemOut[] {
|
||||
if (state.allItems === null) {
|
||||
Promise.resolve(this.refresh());
|
||||
}
|
||||
return state.allItems;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async refresh(): Promise<ItemOut[]> {
|
||||
const result = await this.client.items.getAll();
|
||||
if (result.error) {
|
||||
return result;
|
||||
}
|
||||
|
||||
this.allItems = result.data.items;
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue