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

View File

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

View File

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