parent
5b77968dd1
commit
ebcd50e9a2
2 changed files with 38 additions and 13 deletions
|
|
@ -115,7 +115,7 @@ export default {
|
|||
} else {
|
||||
this.$router.push({name: "bulk", params: {ids: new UrlSafeBase64().encodeIds(ids)}});
|
||||
}
|
||||
|
||||
this.assistantStore.reset();
|
||||
},
|
||||
selectedSupplier(supplier) {
|
||||
this.assistantStore.addSupplier(supplier);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,12 @@ export const useAssistantStore = defineStore('assistant', {
|
|||
const materialIds = this.materials.map((material) => material.id);
|
||||
const supplierIds = this.suppliers.filter(s => s.id.startsWith('s')).map((supplier) => supplier.origId);
|
||||
const userSupplierIds = this.suppliers.filter(s => s.id.startsWith('u')).map((supplier) => supplier.origId);
|
||||
const jsonBody = JSON.stringify({ material: materialIds, supplier: supplierIds, user_supplier: userSupplierIds, from_scratch: this.createEmpty });
|
||||
const jsonBody = JSON.stringify({
|
||||
material: materialIds,
|
||||
supplier: supplierIds,
|
||||
user_supplier: userSupplierIds,
|
||||
from_scratch: this.createEmpty
|
||||
});
|
||||
|
||||
console.log(`Creation body: ${jsonBody}`);
|
||||
|
||||
|
|
@ -36,9 +41,10 @@ export const useAssistantStore = defineStore('assistant', {
|
|||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: jsonBody};
|
||||
body: jsonBody
|
||||
};
|
||||
|
||||
const request = { url: url, params: params};
|
||||
const request = {url: url, params: params};
|
||||
|
||||
const response = await fetch(url, params).catch(e => {
|
||||
this.error = {code: 'Network error.', message: "Please check your internet connection.", trace: null}
|
||||
|
|
@ -47,7 +53,7 @@ export const useAssistantStore = defineStore('assistant', {
|
|||
|
||||
console.error(this.error);
|
||||
const errorStore = useErrorStore();
|
||||
void errorStore.addError(this.error, { store: this, request: request});
|
||||
void errorStore.addError(this.error, {store: this, request: request});
|
||||
|
||||
throw e;
|
||||
});
|
||||
|
|
@ -63,18 +69,23 @@ export const useAssistantStore = defineStore('assistant', {
|
|||
|
||||
console.error(this.error);
|
||||
const errorStore = useErrorStore();
|
||||
void errorStore.addError(this.error, { store: this, request: request});
|
||||
void errorStore.addError(this.error, {store: this, request: request});
|
||||
|
||||
throw e;
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
this.error = {code: data.error.code, title: data.error.title, message: data.error.message, trace: data.error.trace };
|
||||
this.error = {
|
||||
code: data.error.code,
|
||||
title: data.error.title,
|
||||
message: data.error.message,
|
||||
trace: data.error.trace
|
||||
};
|
||||
this.loading = false;
|
||||
|
||||
console.error(this.error);
|
||||
const errorStore = useErrorStore();
|
||||
void errorStore.addError(this.error, { store: this, request: request});
|
||||
void errorStore.addError(this.error, {store: this, request: request});
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -83,6 +94,15 @@ export const useAssistantStore = defineStore('assistant', {
|
|||
return data.map(p => p.id);
|
||||
|
||||
|
||||
},
|
||||
reset() {
|
||||
this.materials = [];
|
||||
this.suppliers = [];
|
||||
this.createEmpty = false;
|
||||
this.loading = false;
|
||||
this.error = null;
|
||||
this.pagination = {};
|
||||
this.query = {};
|
||||
},
|
||||
addSupplier(supplier) {
|
||||
const uid = `${supplier.is_user_node ? 'u' : 's'}${supplier.id}`
|
||||
|
|
@ -128,7 +148,7 @@ export const useAssistantStore = defineStore('assistant', {
|
|||
const headers = new Headers();
|
||||
headers.append('search', encodeURIComponent(query));
|
||||
|
||||
const request = { url: url, params: {method: 'GET'}};
|
||||
const request = {url: url, params: {method: 'GET'}};
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
|
|
@ -139,7 +159,7 @@ export const useAssistantStore = defineStore('assistant', {
|
|||
|
||||
console.error(this.error);
|
||||
const errorStore = useErrorStore();
|
||||
void errorStore.addError(this.error, { store: this, request: request});
|
||||
void errorStore.addError(this.error, {store: this, request: request});
|
||||
|
||||
throw e;
|
||||
});
|
||||
|
|
@ -154,18 +174,23 @@ export const useAssistantStore = defineStore('assistant', {
|
|||
|
||||
console.error(this.error);
|
||||
const errorStore = useErrorStore();
|
||||
void errorStore.addError(this.error, { store: this, request: request});
|
||||
void errorStore.addError(this.error, {store: this, request: request});
|
||||
|
||||
throw e;
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
this.error = {code: data.error.code, title: data.error.title, message: data.error.message, trace: data.error.trace };
|
||||
this.error = {
|
||||
code: data.error.code,
|
||||
title: data.error.title,
|
||||
message: data.error.message,
|
||||
trace: data.error.trace
|
||||
};
|
||||
this.loading = false;
|
||||
|
||||
console.error(this.error);
|
||||
const errorStore = useErrorStore();
|
||||
void errorStore.addError(this.error, { store: this, request: request});
|
||||
void errorStore.addError(this.error, {store: this, request: request});
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue