Generado repositorio para consultar la api #86 #87
| @@ -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> | ||||||
|   | |||||||
| @@ -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; | ||||||
|   | |||||||
| @@ -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; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user