Generado repositorio para consultar la api #86 #87
| @@ -147,10 +147,11 @@ | |||||||
| <script> | <script> | ||||||
|   import CustomerForm from './CreateCustomerModal.vue'; |   import CustomerForm from './CreateCustomerModal.vue'; | ||||||
|   import CasherModal from './CasherModal.vue'; |   import CasherModal from './CasherModal.vue'; | ||||||
|  |   import { inject } from 'vue'; | ||||||
|  |  | ||||||
|  export default { |   export default { | ||||||
|    name: 'DonConfiao', |     name: 'DonConfiao', | ||||||
|    components: { |     components: { | ||||||
|      CustomerForm, |      CustomerForm, | ||||||
|      CasherModal, |      CasherModal, | ||||||
|    }, |    }, | ||||||
| @@ -159,6 +160,7 @@ | |||||||
|    }, |    }, | ||||||
|    data() { |    data() { | ||||||
|      return { |      return { | ||||||
|  |        api: inject('api'), | ||||||
|        valid: false, |        valid: false, | ||||||
|        form_changed: false, |        form_changed: false, | ||||||
|        show_alert_lines: false, |        show_alert_lines: false, | ||||||
| @@ -259,38 +261,35 @@ | |||||||
|          this.purchase.saleline_set[index].measuring_unit = selectedProduct.measuring_unit; |          this.purchase.saleline_set[index].measuring_unit = selectedProduct.measuring_unit; | ||||||
|      }, |      }, | ||||||
|      fetchClients() { |      fetchClients() { | ||||||
|        fetch('/don_confiao/api/customers/') |        this.api.getCustomers() | ||||||
|          .then(response => response.json()) |            .then(data => { | ||||||
|          .then(data => { |              this.clients = data; | ||||||
|            this.clients = data; |            }) | ||||||
|          }) |            .catch(error => { | ||||||
|          .catch(error => { |              console.error(error); | ||||||
|            console.error(error); |            }); | ||||||
|          }); |  | ||||||
|      }, |      }, | ||||||
|        handleNewCustomer(newCustomer){ |        handleNewCustomer(newCustomer){ | ||||||
|            this.clients.push(newCustomer); |            this.clients.push(newCustomer); | ||||||
|            this.purchase.customer = newCustomer.id; |            this.purchase.customer = newCustomer.id; | ||||||
|        }, |        }, | ||||||
|      fetchProducts() { |      fetchProducts() { | ||||||
|        fetch('/don_confiao/api/products/') |        this.api.getProducts() | ||||||
|          .then(response => response.json()) |            .then(data => { | ||||||
|          .then(data => { |              this.products = data; | ||||||
|            this.products = data; |            }) | ||||||
|          }) |            .catch(error => { | ||||||
|          .catch(error => { |              console.error(error); | ||||||
|            console.error(error); |            }); | ||||||
|          }); |  | ||||||
|      }, |      }, | ||||||
|      fetchPaymentMethods() { |      fetchPaymentMethods() { | ||||||
|        fetch('/don_confiao/payment_methods/all/select_format') |        this.api.getPaymentMethods() | ||||||
|          .then(response => response.json()) |            .then(data => { | ||||||
|          .then(data => { |              this.payment_methods = data; | ||||||
|            this.payment_methods = data; |            }) | ||||||
|          }) |            .catch(error => { | ||||||
|          .catch(error => { |              console.error(error); | ||||||
|            console.error(error); |            }); | ||||||
|          }); |  | ||||||
|      }, |      }, | ||||||
|      addLine() { |      addLine() { | ||||||
|        this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0, measuring_unit: ''}); |        this.purchase.saleline_set.push({ product: '', unit_price: 0, quantity:0, measuring_unit: ''}); | ||||||
| @@ -347,7 +346,7 @@ | |||||||
|      }, |      }, | ||||||
|    }, |    }, | ||||||
|      mounted() { |      mounted() { | ||||||
|          this.fetchClients();  // Llama a fetchClients al montar el componente |          this.fetchClients(); | ||||||
|      } |      } | ||||||
|  }; |  }; | ||||||
| </script> | </script> | ||||||
|   | |||||||
| @@ -9,11 +9,17 @@ import { registerPlugins } from '@/plugins' | |||||||
|  |  | ||||||
| // Components | // Components | ||||||
| import App from './App.vue' | import App from './App.vue' | ||||||
|  | import ApiImplementation from './services/api-implementation'; | ||||||
|  |  | ||||||
| // Composables | // Composables | ||||||
| import { createApp } from 'vue' | import { createApp } from 'vue' | ||||||
|  |  | ||||||
| const app = createApp(App) | process.env.API_IMPLEMENTATION = 'django'; | ||||||
|  | let apiImplementation = new ApiImplementation(); | ||||||
|  | const api = apiImplementation.getApi(); | ||||||
|  |  | ||||||
|  | const app = createApp(App); | ||||||
|  | app.provide('api', api); | ||||||
|  |  | ||||||
| registerPlugins(app) | registerPlugins(app) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -0,0 +1,21 @@ | |||||||
|  | import DjangoApi from './django-api'; | ||||||
|  | import Api from './api'; | ||||||
|  |  | ||||||
|  | class ApiImplementation { | ||||||
|  |   constructor() { | ||||||
|  |     const implementation = process.env.API_IMPLEMENTATION; | ||||||
|  |     let apiImplementation; | ||||||
|  |     if (implementation === 'django') { | ||||||
|  |       apiImplementation = new DjangoApi(); | ||||||
|  |     } else { | ||||||
|  |       throw new Error("API implementation don't configured"); | ||||||
|  |     } | ||||||
|  |     this.api = new Api(apiImplementation); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getApi() { | ||||||
|  |     return this.api; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export default ApiImplementation; | ||||||
| @@ -0,0 +1,19 @@ | |||||||
|  | class Api { | ||||||
|  |   constructor (apiImplementation) { | ||||||
|  |     this.apiImplementation = apiImplementation; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getCustomers() { | ||||||
|  |     return this.apiImplementation.getCustomers(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getProducts() { | ||||||
|  |     return this.apiImplementation.getProducts(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getPaymentMethods() { | ||||||
|  |     return this.apiImplementation.getPaymentMethods(); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export default Api; | ||||||
| @@ -0,0 +1,42 @@ | |||||||
|  | class DjangoApi { | ||||||
|  |   getCustomers() { | ||||||
|  |     return new Promise((resolve, reject) => { | ||||||
|  |       fetch('/don_confiao/api/customers/') | ||||||
|  |         .then(response => response.json()) | ||||||
|  |         .then(data => { | ||||||
|  |           resolve(data); | ||||||
|  |         }) | ||||||
|  |         .catch(error => { | ||||||
|  |           reject(error); | ||||||
|  |         }); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getProducts() { | ||||||
|  |     return new Promise((resolve, reject) => { | ||||||
|  |       fetch('/don_confiao/api/products/') | ||||||
|  |          .then(response => response.json()) | ||||||
|  |          .then(data => { | ||||||
|  |            resolve(data); | ||||||
|  |          }) | ||||||
|  |          .catch(error => { | ||||||
|  |            reject(error); | ||||||
|  |          }); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   getPaymentMethods() { | ||||||
|  |     return new Promise((resolve, reject) => { | ||||||
|  |       fetch('/don_confiao/payment_methods/all/select_format') | ||||||
|  |          .then(response => response.json()) | ||||||
|  |          .then(data => { | ||||||
|  |            resolve(data); | ||||||
|  |          }) | ||||||
|  |          .catch(error => { | ||||||
|  |            reject(error); | ||||||
|  |          }); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export default DjangoApi; | ||||||
		Reference in New Issue
	
	Block a user