From fab7d63333b86b9fe0f1c52d2c642b52bbf506c0 Mon Sep 17 00:00:00 2001 From: gabrhr <73925454+gabrhr@users.noreply.github.com> Date: Mon, 6 Jun 2022 11:35:56 -0500 Subject: Add CRUD Camiones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - están ok funcionando: listar, insertar, editar, eliminar #TODO - añadir todos los puntos - Mejorar el path del punto con funcion - añadir tiempos segun distancia - estetica al final (camion, colores, etc) - Arreglar combos - Añadir los reducer de pedidos, rutas, almacen Camiones CRUD - ver codigo de camion corelativo - añadir Ciudad origen --- front/odiparpack/app/actions/actionTypes.js | 5 ++ front/odiparpack/app/actions/camion.js | 74 ++++++++++++++++++++++++++++- front/odiparpack/app/actions/tipoCamion.js | 19 ++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 front/odiparpack/app/actions/tipoCamion.js (limited to 'front/odiparpack/app/actions') diff --git a/front/odiparpack/app/actions/actionTypes.js b/front/odiparpack/app/actions/actionTypes.js index 11884c0..36d1b07 100644 --- a/front/odiparpack/app/actions/actionTypes.js +++ b/front/odiparpack/app/actions/actionTypes.js @@ -93,3 +93,8 @@ export const LISTA_PEDIDO = 'LISTA_PEDIDO'; export const LISTA_ALMACEN = 'LISTA_ALMACEN'; //Odi Camion export const LISTA_CAMION = 'LISTA_CAMION'; +export const NUEVO_CAMION = 'NUEVO_CAMION'; +export const ACTUALIZAR_CAMION = 'ACTUALIZAR_CAMION'; +export const ELIMINAR_CAMION = 'ELIMINAR_CAMION'; + +export const LISTA_TIPO_CAMION = 'LISTA_TIPO_CAMION'; diff --git a/front/odiparpack/app/actions/camion.js b/front/odiparpack/app/actions/camion.js index 6fdd2c6..dc60eee 100644 --- a/front/odiparpack/app/actions/camion.js +++ b/front/odiparpack/app/actions/camion.js @@ -1,6 +1,12 @@ import { - getCamionAPI + getCamionAPI, + insertarCamionAPI, + editarCamionAPI, + eliminarCamionAPI } from 'ba-api/camion'; +import { + getTipoCamionXNombreAPI +} from 'ba-api/tipoCamion'; import * as types from './actionTypes' export const setCamiones = (payload) => ({ @@ -8,6 +14,21 @@ export const setCamiones = (payload) => ({ payload }); +export const insertCamiones = (payload) => ({ + type: types.NUEVO_CAMION, + payload +}); + +export const updateCamiones = (payload) => ({ + type: types.ACTUALIZAR_CAMION, + payload +}); + +export const deleteCamiones = (payload) => ({ + type: types.ELIMINAR_CAMION, + payload +}); + /***************************************/ export function b2fCamiones(x){ const {...other} = x @@ -23,6 +44,24 @@ export function b2fCamiones(x){ } } +export function f2bCamion(x, tipo){ + console.log("Antes", tipo) + console.log("data new", x.get('id')) + const data = { + id: x.get('id')? x.get('id'): undefined, + placa: x.get('placa'), + codigo: "A0005", + estado: x.get('estado'), + kilometraje: 50.0, + tipoCamion: { + id: tipo.id, + nombre: tipo.nombre, + capacidad: tipo.capacidad + } + } + return data +} + /***************************************/ export const getCamiones = () => async dispatch => { @@ -37,3 +76,36 @@ export const getCamiones = () => async dispatch => { console.log(e) } } + +export const insertarCamion = (data) => async dispatch => { + try{ + const resTipo = await getTipoCamionXNombreAPI(data.get('tipo')); + const res = await insertarCamionAPI(f2bCamion(data, resTipo.data)); + dispatch(insertCamiones({res})) + return res; + }catch(e){ + console.log(e) + } +} + +export const editarCamion = (data) => async dispatch => { + try{ + const resTipo = await getTipoCamionXNombreAPI(data.get('tipo')); + const res = await editarCamionAPI(f2bCamion(data, resTipo.data)); + dispatch(updateCamiones({res})) + return res; + }catch(e){ + console.log(e) + } +} + +export const eliminarCamion = (data) => async dispatch => { + try{ + //Envia id + const res = await eliminarCamionAPI(data); + dispatch(deleteCamiones({res})) + return res; + }catch(e){ + console.log(e) + } +} diff --git a/front/odiparpack/app/actions/tipoCamion.js b/front/odiparpack/app/actions/tipoCamion.js new file mode 100644 index 0000000..06a47d6 --- /dev/null +++ b/front/odiparpack/app/actions/tipoCamion.js @@ -0,0 +1,19 @@ +import { + getTiposCamionAPI +} from 'ba-api/tipoCamion'; +import * as types from './actionTypes' + +export const setTipoCamiones = (payload) => ({ + type: types.LISTA_TIPO_CAMION, + payload +}); + +export const getTipoCamiones = () => async dispatch => { + try{ + const res = await getTiposCamionAPI(); + dispatch(setTipoCamiones({res})) + return res; + }catch(e){ + console.log(e) + } +} \ No newline at end of file -- cgit v1.2.3