diff options
| author | Dayana31 <[email protected]> | 2022-06-06 18:22:06 -0500 |
|---|---|---|
| committer | Dayana31 <[email protected]> | 2022-06-06 18:22:06 -0500 |
| commit | c10432bd66dfbf040662e9c8203956ac3614f4ca (patch) | |
| tree | 88c739cdb9650408458ee300ca03a7fc7746cb9b /front/odiparpack/app/actions/camion.js | |
| parent | f3c1a8c5dcc3c482205f34332a9d673b35b4cfb0 (diff) | |
| parent | fab7d63333b86b9fe0f1c52d2c642b52bbf506c0 (diff) | |
| download | DP1_project-c10432bd66dfbf040662e9c8203956ac3614f4ca.tar.gz DP1_project-c10432bd66dfbf040662e9c8203956ac3614f4ca.tar.bz2 DP1_project-c10432bd66dfbf040662e9c8203956ac3614f4ca.zip | |
Merge branch 'gabshr' into dayana
Diffstat (limited to 'front/odiparpack/app/actions/camion.js')
| -rw-r--r-- | front/odiparpack/app/actions/camion.js | 74 |
1 files changed, 73 insertions, 1 deletions
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) + } +} |
