corretto altre cose (workbox mancante)

This commit is contained in:
Surya Paolo
2025-05-15 21:41:25 +02:00
parent 685bc34bd0
commit daeb865e93
8 changed files with 141 additions and 410500 deletions

View File

@@ -26,25 +26,28 @@ export const useCatalogStore = defineStore('CatalogStore', {
}),
getters: {
getCatalogById: (state) => async (id: string) => {
// carica in memoria il catalogo singolo
// se non lo trovo, allora lo carica dal server
let cat = state.catalogs.find((cat: ICatalog) => cat._id === id);
if ((cat && !cat.prodotti_caricati_inmem) || !cat) {
// Lo carica dal server
cat = await this.loadCatalogById(id);
}
return cat;
getCatalogById: (state) => (id: string) => {
return state.catalogs.find((cat: ICatalog) => cat._id === id) || null;
},
},
actions: {
async fetchCatalogById(id: string) {
// Controlla se è già in memoria
let cat = this.getCatalogById(id);
if (!cat || !cat.prodotti_caricati_inmem) {
// Carica dal server
const ris = await this.loadCatalogById(id);
if (ris) {
// Aggiorna lo store con i dati ricevuti
this.updateDataCatalog(ris);
cat = this.getCatalogById(id);
}
}
return cat;
},
async loadCatalogById(id: string) {
const userStore = useUserStore();
const globalStore = useGlobalStore();
let ris = null;
@@ -54,15 +57,12 @@ export const useCatalogStore = defineStore('CatalogStore', {
console.log('catalogs', res.data.catalog);
if (res.data.catalog) {
// console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
this.updateDataCatalog(res);
return res.data.product;
} else {
return null;
}
return null;
})
.catch((error) => {
console.log('error loadCatalogById', error);
userStore.setErrorCatch(error);
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error);
});