160 lines
4.5 KiB
JavaScript
160 lines
4.5 KiB
JavaScript
import AuthService from "@/services/auth";
|
|
import http from "@/services/http";
|
|
|
|
class DjangoApi {
|
|
constructor() {
|
|
this.base = import.meta.env.VITE_DJANGO_BASE_URL;
|
|
}
|
|
|
|
getRequest(url) {
|
|
return http.get(url).then((r) => r.data);
|
|
}
|
|
|
|
postRequest(url, payload) {
|
|
return http.post(url, payload).then((r) => r.data);
|
|
}
|
|
|
|
patchRequest(url, payload) {
|
|
return http.patch(url, payload).then((r) => r.data);
|
|
}
|
|
|
|
getCustomers() {
|
|
const url = this.base + "/don_confiao/api/customers/";
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
getProducts(active = 'all') {
|
|
let url = this.base + "/don_confiao/api/products/";
|
|
|
|
// Agregar query parameter según filtro
|
|
if (active !== 'all') {
|
|
url += `?active=${active}`;
|
|
}
|
|
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
updateProduct(productId, data) {
|
|
const url = this.base + `/don_confiao/api/products/${productId}/`;
|
|
return this.patchRequest(url, data);
|
|
}
|
|
|
|
getPaymentMethods() {
|
|
const url =
|
|
this.base + "/don_confiao/payment_methods/all/select_format";
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
getSummaryPurchase(purchaseId) {
|
|
const url =
|
|
this.base + `/don_confiao/resumen_compra_json/${purchaseId}`;
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
getSummaryCatalogPurchase(purchaseId) {
|
|
const url =
|
|
this.base + `/don_confiao/resumen_compra_catalogo_json/${purchaseId}`;
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
getPurchasesForReconciliation() {
|
|
const url = this.base + "/don_confiao/purchases/for_reconciliation";
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
getListReconcliations(page, itemsPerPage) {
|
|
const url =
|
|
this.base +
|
|
`/don_confiao/api/reconciliate_jar/?page=${page}&page_size=${itemsPerPage}`;
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
getReconciliation(reconciliationId) {
|
|
const url =
|
|
this.base +
|
|
`/don_confiao/api/reconciliate_jar/${reconciliationId}/`;
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
createPurchase(purchase) {
|
|
const url = this.base + "/don_confiao/api/sales/";
|
|
return this.postRequest(url, purchase);
|
|
}
|
|
|
|
createCatalogPurchase(purchase) {
|
|
const url = this.base + "/don_confiao/api/catalog_sales/";
|
|
return this.postRequest(url, purchase);
|
|
}
|
|
|
|
createReconciliationJar(reconciliation) {
|
|
const url = this.base + "/don_confiao/reconciliate_jar";
|
|
return this.postRequest(url, reconciliation);
|
|
}
|
|
|
|
createCustomer(customer) {
|
|
const url = this.base + "/don_confiao/api/customers/";
|
|
return this.postRequest(url, customer);
|
|
}
|
|
|
|
getCSVForTryton() {
|
|
const url = this.base + "/don_confiao/api/sales/for_tryton";
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
getProductsFromTryton() {
|
|
const url = this.base + "/don_confiao/api/importar_productos_de_tryton";
|
|
return this.postRequest(url, {});
|
|
}
|
|
|
|
getCustomersFromTryton() {
|
|
const url = this.base + "/don_confiao/api/importar_clientes_de_tryton";
|
|
return this.postRequest(url, {});
|
|
}
|
|
|
|
sendSalesToTryton() {
|
|
const url = this.base + "/don_confiao/api/enviar_ventas_a_tryton";
|
|
return this.postRequest(url, {});
|
|
}
|
|
|
|
sendCatalogSalesToTryton() {
|
|
const url = this.base + "/don_confiao/api/enviar_catalog_sales_a_tryton";
|
|
return this.postRequest(url, {});
|
|
}
|
|
|
|
getCatalogSales() {
|
|
const url = this.base + "/don_confiao/api/catalog_sales/";
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
getCurrentUser() {
|
|
const url = this.base + "/api/users/me/";
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
getCatalogueImages() {
|
|
const url = this.base + "/don_confiao/api/catalogue_images/";
|
|
return this.getRequest(url);
|
|
}
|
|
|
|
createCatalogueImage(data) {
|
|
const url = this.base + "/don_confiao/api/catalogue_images/";
|
|
return http.post(url, data, {
|
|
headers: { 'Content-Type': undefined },
|
|
}).then((r) => r.data);
|
|
}
|
|
|
|
updateCatalogueImage(id, data) {
|
|
const url = this.base + `/don_confiao/api/catalogue_images/${id}/`;
|
|
return http.put(url, data, {
|
|
headers: { 'Content-Type': undefined },
|
|
}).then((r) => r.data);
|
|
}
|
|
|
|
deleteCatalogueImage(id) {
|
|
const url = this.base + `/don_confiao/api/catalogue_images/${id}/`;
|
|
return http.delete(url).then((r) => r.data);
|
|
}
|
|
}
|
|
|
|
export default DjangoApi;
|