summaryrefslogtreecommitdiffstats
path: root/front/odiparpack/app/actions
diff options
context:
space:
mode:
authorgabrhr <[email protected]>2022-06-06 11:35:56 -0500
committergabrhr <[email protected]>2022-06-06 11:35:56 -0500
commitfab7d63333b86b9fe0f1c52d2c642b52bbf506c0 (patch)
tree59e3541bbe92c67fdf54bc0ef6efabb0a4fe1d6c /front/odiparpack/app/actions
parent3a91d18704ee5ac783b398b1589ee2b14ea35321 (diff)
downloadDP1_project-fab7d63333b86b9fe0f1c52d2c642b52bbf506c0.tar.gz
DP1_project-fab7d63333b86b9fe0f1c52d2c642b52bbf506c0.tar.bz2
DP1_project-fab7d63333b86b9fe0f1c52d2c642b52bbf506c0.zip
Add CRUD Camiones
- 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
Diffstat (limited to 'front/odiparpack/app/actions')
-rw-r--r--front/odiparpack/app/actions/actionTypes.js5
-rw-r--r--front/odiparpack/app/actions/camion.js74
-rw-r--r--front/odiparpack/app/actions/tipoCamion.js19
3 files changed, 97 insertions, 1 deletions
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