#84 refactor(frontend): extact to method django-api.
This commit is contained in:
parent
8f9917c3a4
commit
34259921d9
@ -1,54 +1,22 @@
|
|||||||
class DjangoApi {
|
class DjangoApi {
|
||||||
getCustomers() {
|
getCustomers() {
|
||||||
return new Promise((resolve, reject) => {
|
const url = '/don_confiao/api/customers/';
|
||||||
fetch('/don_confiao/api/customers/')
|
return this.getRequest(url);
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
resolve(data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getProducts() {
|
getProducts() {
|
||||||
return new Promise((resolve, reject) => {
|
const url = '/don_confiao/api/products/';
|
||||||
fetch('/don_confiao/api/products/')
|
return this.getRequest(url);
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
resolve(data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPaymentMethods() {
|
getPaymentMethods() {
|
||||||
return new Promise((resolve, reject) => {
|
const url = '/don_confiao/payment_methods/all/select_format';
|
||||||
fetch('/don_confiao/payment_methods/all/select_format')
|
return this.getRequest(url);
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
resolve(data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSummaryPurchase(purchaseId) {
|
getSummaryPurchase(purchaseId) {
|
||||||
return new Promise ((resolve, reject) => {
|
const url = `/don_confiao/resumen_compra_json/${purchaseId}`;
|
||||||
fetch(`/don_confiao/resumen_compra_json/${purchaseId}`)
|
return this.getRequest(url);
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
resolve(data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createPurchase(purchase) {
|
createPurchase(purchase) {
|
||||||
@ -75,6 +43,19 @@ class DjangoApi {
|
|||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRequest(url) {
|
||||||
|
return new Promise ((resolve, reject) => {
|
||||||
|
fetch(url)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
resolve(data);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DjangoApi;
|
export default DjangoApi;
|
||||||
|
Loading…
Reference in New Issue
Block a user