#84 refactor(front): moved to api create reconciliation jar.

This commit is contained in:
Mono Mono 2025-01-11 14:05:01 -05:00
parent d9f6be8b54
commit 9ad8ff8706
3 changed files with 47 additions and 43 deletions

View File

@ -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', console.log('Cuadre enviado:', data);
headers: { this.$router.push({path: "/"});
'Content-Type': 'application/json' })
}, .catch(error => console.error('Error:', error));
body: JSON.stringify(this.reconciliation),
});
if (response.ok) {
const data = await response.json();
console.log('Cuadre enviado:', data);
this.$router.push({path: "/"});
} else {
console.error('Error al enviar el cuadre', response.statusText);
}
} catch (error) {
console.error('Error de red:', error);
}
} }
}, }
}, },
} }
</script> </script>

View File

@ -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;

View File

@ -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: { createReconciliationJar(reconciliation) {
'Content-Type': 'application/json', const url = '/don_confiao/reconciliate_jar';
}, return this.postRequest(url, reconciliation);
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);
}
});
}
}).catch(error => reject(error));
});
} }
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;