summaryrefslogtreecommitdiffstats
path: root/front/odiparpack/app/utils
diff options
context:
space:
mode:
authorDayana31 <[email protected]>2022-06-01 16:43:23 -0500
committerDayana31 <[email protected]>2022-06-01 16:43:23 -0500
commitec0c33156713e51c64f2a9de4f932cd5507c654b (patch)
treecc46421686a49bbc0a0c343e460c13a21af1015d /front/odiparpack/app/utils
parent6971201caffc2fccee5bfb12e88e5510c85eeb49 (diff)
parente9cb09907f8dbc9a4a64549a3ea4d1d8313e7c25 (diff)
downloadDP1_project-ec0c33156713e51c64f2a9de4f932cd5507c654b.tar.gz
DP1_project-ec0c33156713e51c64f2a9de4f932cd5507c654b.tar.bz2
DP1_project-ec0c33156713e51c64f2a9de4f932cd5507c654b.zip
Merge branch 'develop' into dayana
Diffstat (limited to 'front/odiparpack/app/utils')
-rw-r--r--front/odiparpack/app/utils/odipar/api.js101
-rw-r--r--front/odiparpack/app/utils/odipar/constants.js9
-rw-r--r--front/odiparpack/app/utils/odipar/menu.js51
3 files changed, 161 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..50c2beb
--- /dev/null
+++ b/front/odiparpack/app/utils/odipar/api.js
@@ -0,0 +1,101 @@
+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 = {}) {
+ //console.log("apiReq - ANTES DE PROMESA")
+ headers = {
+ ...headers
+ }
+ if (method === 'get' || method === 'delete') {
+ data = {
+ ...requestOptions,
+ params: data,
+ paramsSerializer: function (params) {
+ return qs.stringify(params, { arrayFormat: 'repeat' })
+ },
+ headers
+ }
+ }
+
+ return axios[method](endPoint, data, { headers })
+}
+
+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("addMessageCurry -SUCCESS MSG")
+ 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..1b280b8
--- /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/almacenes',
+ 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