#84 refactor(front): moved to api createCustomer.

This commit is contained in:
Mono Mono 2025-01-11 15:44:07 -05:00
parent 9ad8ff8706
commit 871a82eee5
3 changed files with 17 additions and 21 deletions

View File

@ -45,6 +45,7 @@
data() { data() {
return { return {
showModal: false, showModal: false,
api: inject('api'),
valid: false, valid: false,
customer: { customer: {
name: '', name: '',
@ -72,25 +73,13 @@
async submitForm() { async submitForm() {
console.log(this.customer) console.log(this.customer)
if (this.$refs.form.validate()) { if (this.$refs.form.validate()) {
try { this.api.createCustomer(this.customer)
const response = await fetch('/don_confiao/api/customers/', { .then(data => {
method: 'POST', console.log('Cliente Guardado:', data);
headers: { this.$emit('customerCreated', data);
'Content-Type': 'application/json', this.closeModal();
}, })
body: JSON.stringify(this.customer), .catch(error => console.error('Error:', error));
});
if (response.ok) {
const data = await response.json();
console.log('Cliente Guardado:', data);
this.$emit('customerCreated', data);
this.closeModal();
} else {
console.error('Error al Crear el Cliente:', response.statusText);
}
} catch (error) {
console.error('Error de red:', error);
}
} }
}, },
resetForm() { resetForm() {

View File

@ -30,6 +30,10 @@ class Api {
createReconciliationJar(reconciliation) { createReconciliationJar(reconciliation) {
return this.apiImplementation.createReconciliationJar(reconciliation); return this.apiImplementation.createReconciliationJar(reconciliation);
} }
createCustomer(customer) {
return this.apiImplementation.createCustomer(customer);
}
} }
export default Api; export default Api;

View File

@ -34,6 +34,11 @@ class DjangoApi {
return this.postRequest(url, reconciliation); return this.postRequest(url, reconciliation);
} }
createCustomer(customer) {
const url = '/don_confiao/api/customers/';
return this.postRequest(url, customer);
}
getRequest(url) { getRequest(url) {
return new Promise ((resolve, reject) => { return new Promise ((resolve, reject) => {
fetch(url) fetch(url)
@ -45,8 +50,6 @@ class DjangoApi {
reject(error); reject(error);
}); });
}); });
} }
postRequest(url, content) { postRequest(url, content) {