#84 refactor(frontend): send purchase moved to repository.
This commit is contained in:
parent
6d6322b0cd
commit
fcb83d05fb
@ -310,27 +310,15 @@
|
|||||||
async submit() {
|
async submit() {
|
||||||
this.$refs.purchase.validate();
|
this.$refs.purchase.validate();
|
||||||
if (this.valid) {
|
if (this.valid) {
|
||||||
try {
|
this.api.createPurchase(this.purchase)
|
||||||
const response = await fetch('/don_confiao/api/sales/', {
|
.then(data => {
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(this.purchase),
|
|
||||||
});
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
console.log('Compra enviada:', data);
|
console.log('Compra enviada:', data);
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
path: "/summary_purchase",
|
path: "/summary_purchase",
|
||||||
query : {id: parseInt(data.id)}
|
query : {id: parseInt(data.id)}
|
||||||
});
|
});
|
||||||
} else {
|
})
|
||||||
console.error('Error al enviar la compra:', response.statusText);
|
.catch(error => console.error('Error al enviarl la compra:', error));
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error de red:', error);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.show_alert_purchase = true;
|
this.show_alert_purchase = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -14,6 +14,10 @@ class Api {
|
|||||||
getPaymentMethods() {
|
getPaymentMethods() {
|
||||||
return this.apiImplementation.getPaymentMethods();
|
return this.apiImplementation.getPaymentMethods();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createPurchase(purchase) {
|
||||||
|
return this.apiImplementation.createPurchase(purchase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Api;
|
export default Api;
|
||||||
|
@ -37,6 +37,31 @@ class DjangoApi {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createPurchase(purchase) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
console.log('compra a enviar:', 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(error => reject(error));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DjangoApi;
|
export default DjangoApi;
|
||||||
|
Loading…
Reference in New Issue
Block a user