#84 refactor(front): moved to api create reconciliation jar.
This commit is contained in:
parent
d9f6be8b54
commit
9ad8ff8706
@ -187,27 +187,14 @@
|
|||||||
async submit() {
|
async submit() {
|
||||||
this.$refs.taker.validate();
|
this.$refs.taker.validate();
|
||||||
if (this.valid) {
|
if (this.valid) {
|
||||||
try {
|
this.api.createReconciliationJar(this.reconciliation)
|
||||||
const response = await fetch('/don_confiao/reconciliate_jar', {
|
.then(data => {
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(this.reconciliation),
|
|
||||||
});
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
console.log('Cuadre enviado:', data);
|
console.log('Cuadre enviado:', data);
|
||||||
this.$router.push({path: "/"});
|
this.$router.push({path: "/"});
|
||||||
} else {
|
})
|
||||||
console.error('Error al enviar el cuadre', response.statusText);
|
.catch(error => console.error('Error:', error));
|
||||||
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error de red:', error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -26,6 +26,10 @@ class Api {
|
|||||||
createPurchase(purchase) {
|
createPurchase(purchase) {
|
||||||
return this.apiImplementation.createPurchase(purchase);
|
return this.apiImplementation.createPurchase(purchase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createReconciliationJar(reconciliation) {
|
||||||
|
return this.apiImplementation.createReconciliationJar(reconciliation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Api;
|
export default Api;
|
||||||
|
@ -25,28 +25,13 @@ class DjangoApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createPurchase(purchase) {
|
createPurchase(purchase) {
|
||||||
return new Promise((resolve, reject) => {
|
const url = '/don_confiao/api/sales/';
|
||||||
console.log('compra a enviar:', purchase);
|
return this.postRequest(url, purchase);
|
||||||
fetch('/don_confiao/api/sales/', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(purchase),
|
|
||||||
}).then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
reject(new Error(`Error ${response.status}: ${response.statusText}`));
|
|
||||||
} else {
|
|
||||||
response.json().then(data => {
|
|
||||||
if (!data) {
|
|
||||||
reject(new Error('La respuesta no es un JSON válido'));
|
|
||||||
} else {
|
|
||||||
resolve(data);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
createReconciliationJar(reconciliation) {
|
||||||
}).catch(error => reject(error));
|
const url = '/don_confiao/reconciliate_jar';
|
||||||
});
|
return this.postRequest(url, reconciliation);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRequest(url) {
|
getRequest(url) {
|
||||||
@ -60,7 +45,35 @@ class DjangoApi {
|
|||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
postRequest(url, content) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(content)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
reject(new Error(`Error ${response.status}: ${response.statusText}`));
|
||||||
|
} else {
|
||||||
|
response.json().then(data => {
|
||||||
|
if (!data) {
|
||||||
|
reject(new Error('La respuesta no es un JSON válido'));
|
||||||
|
} else {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => reject(error));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DjangoApi;
|
export default DjangoApi;
|
||||||
|
Loading…
Reference in New Issue
Block a user