diff options
Diffstat (limited to 'front/odiparpack/app/utils/odipar')
| -rw-r--r-- | front/odiparpack/app/utils/odipar/api.js | 113 | ||||
| -rw-r--r-- | front/odiparpack/app/utils/odipar/constants.js | 9 | ||||
| -rw-r--r-- | front/odiparpack/app/utils/odipar/menu.js | 51 |
3 files changed, 173 insertions, 0 deletions
diff --git a/front/odiparpack/app/utils/odipar/api.js b/front/odiparpack/app/utils/odipar/api.js new file mode 100644 index 0000000..ea5e617 --- /dev/null +++ b/front/odiparpack/app/utils/odipar/api.js @@ -0,0 +1,113 @@ +import Axios from 'axios' +import {apiUrl} from './constants'; +import qs from "query-string"; +import { openSuccessMessage, openErrorMessage } from 'ba-actions/message'; + +export function getHeaders() { + let session = getSession(); + return { + //Authorization: `Token ${(session && session.accessToken) || null}` + } +} + + +export function getSession() { + if (window && window.localStorage) { + return window.localStorage.getObject('session'); + } + + return null; +} + +export function saveSession(value) { + if (window && window.localStorage) { + return window.localStorage.saveObject('session', value); + } + + return null; +} + +export function apiReq(endPoint, data, method, headers, requestOptions = {}) { + return new Promise((res, rej) => { + + headers = { + ...headers + } + if (method === 'get' || method === 'delete') { + data = { + ...requestOptions, + params: data, + paramsSerializer: function (params) { + return qs.stringify(params, { arrayFormat: 'repeat' }) + }, + headers + } + } + + Axios[method](endPoint, data, { headers }).then((result) => { + let { data } = result; + console.log("aca en la promesa ps") + if (data.status === false) { + return rej(data); + } + + return res(data); + }).catch((err) => { + return rej(err); + }); + }) +} + +export function generateUrl(path) { + return apiUrl + path; +} + +export function apiPost(endPoint, data, headers = {}) { + return apiReq(generateUrl(endPoint), data, 'post', headers); +} + +export function apiDelete(endPoint, data, headers = {}) { + return apiReq(generateUrl(endPoint), data, 'delete', headers); +} + +export function apiGet(endPoint, data, headers = {}, requestOptions) { + return apiReq(generateUrl(endPoint), data, 'get', headers, requestOptions); +} + +export function apiPut(endPoint, data, headers = {}) { + return apiReq(generateUrl(endPoint), data, 'put', headers); +} + + +export function addMessageCurry(promise, dispatch, errorMsg = '', successMsg = '', showError = true) { + return new Promise( + (resolve, reject) => { + + promise + .then(response => { + + if (successMsg) { + console.log("mensajitooooo=?????") + dispatch( + openSuccessMessage(successMsg) + ) + } + + resolve(response) + }) + .catch( + err => { + if(showError) { + dispatch( + openErrorMessage(errorMsg || ((err.response && err.response.data.message) || 'Server encountered an error')) + ) + } + + reject(err) + } + ) + + } + ) + +}
\ No newline at end of file diff --git a/front/odiparpack/app/utils/odipar/constants.js b/front/odiparpack/app/utils/odipar/constants.js new file mode 100644 index 0000000..73f3521 --- /dev/null +++ b/front/odiparpack/app/utils/odipar/constants.js @@ -0,0 +1,9 @@ +//export const apiUrl = `${config.api}api/v1/`; +export const apiUrl = 'http://localhost:8083/'; + +//mensaje +export function partial(fn, ...presetArgs) { + return function partiallyApplied(...laterArgs) { + return fn(...presetArgs, ...laterArgs); + }; +}
\ No newline at end of file diff --git a/front/odiparpack/app/utils/odipar/menu.js b/front/odiparpack/app/utils/odipar/menu.js new file mode 100644 index 0000000..eca2600 --- /dev/null +++ b/front/odiparpack/app/utils/odipar/menu.js @@ -0,0 +1,51 @@ +module.exports = [ + { + key: 'seguimiento', + name: 'Seguimiento', + icon: 'near_me', + link: '/app/dashboard-v2', + child: [ ] + }, + { + key: 'pedidos', + name: 'Pedidos', + icon: 'inventory_2', + link: '/app/pedidos', + child: [ ] + }, + { + key: 'camiones', + name: 'Camiones', + icon: 'local_shipping', + link: '/app/layouts/grid', + child: [ ] + }, + { + key: 'almacenes', + name: 'Almacenes', + icon: 'warehouse', + link: '/app/tables/crud-table', + child: [ ] + }, + { + key: 'red_tramos', + name: 'Red de Tramos', + icon: 'location_on', + link: '/app/forms/reduxform', + child: [ ] + }, + { + key: 'otros', + name: 'Otros parámetros', + icon: 'settings', + link: '/app/ui/icons', + child: [ ] + }, + { + key: 'simulacion', + name: 'Simulación', + icon: 'fast_forward', + link: '/app/pages/calendar', + child: [ ] + } + ];
\ No newline at end of file |
