Generado repositorio para consultar la api #86 #87
| @@ -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() { | ||||
|   | ||||
| @@ -30,6 +30,10 @@ class Api { | ||||
|   createReconciliationJar(reconciliation) { | ||||
|     return this.apiImplementation.createReconciliationJar(reconciliation); | ||||
|   } | ||||
|  | ||||
|   createCustomer(customer) { | ||||
|     return this.apiImplementation.createCustomer(customer); | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default Api; | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user