$myvar2 = $req->getParsedBody()['myvar']; //checks _POST [IS PSR-7 compliant] $myvar3 = $req->getQueryParams()['myvar']; //checks _GET [IS PSR-7 compliant] echo "1:".$myvar1; echo "2:".$myvar2; echo "3:".$myvar3; }); */ $app->get('/servicios', 'getServicios'); $app->get('/servicios/{id}', function (Request $req, Response $res) { $id = $req->getAttribute('id'); $rs_data = getServicio($id); if ($rs_data === false) { return $res->withStatus(400)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(400, 'ERR_DATABASE', 'Error al consultar la base de datos.'))); } else { return $res->withStatus(200)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(200, '', '', getServicio($id)))); } }); $app->get('/servicios/search/:query', 'findServicioByName'); $app->post('/servicios', 'addServicio'); $app->put('/servicios/:id', 'updateServicio'); $app->delete('/servicios/:id', 'deleteServicio'); $app->post('/datos', function (Request $req, Response $res, $args = []) { $args = $req->getParsedBody(); //var_dump($args); //echo $args['usr']; /* return $res->withHeader( 'Content-Type', 'application/json' );
function updProducto($req, $res) { $db = getCnxn(); // REQUERIDO PARA VALIDA CREDENCIALES $user_id = null; $user = $req['user']; $pwd = $req['pwd']; // <--------------------------------- $id = $req['id']; $empresa = $req['empresa']; $nombre = $req['nombre']; $descripcion = $req['descripcion']; $sku_owner = $req['sku_negocio']; $sku_provider = $req['sku_proveedor']; $precio = $req['precio']; $proveedor = $req['proveedor']; $unidad = $req['unidad']; $existencia = $req['existencia']; $existencia_min = $req['existencia_minima']; $imagen = $req['imagen']; $date_current = date("Y-m-d H:i:s"); // VALIDA CREDENCIALES $rs_data = validaCredenciales($user, $pwd); if ($rs_data === false) { return $res->withStatus(400)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(400, 'ERR_DATABASE', 'Error al consultar la base de datos.'))); } else { $data_rows = intval(count($rs_data)); if ($data_rows > 0) { $user_data = $rs_data[0]; $user_id = $user_data['id']; } else { return $res->withStatus(400)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(400, '', '', null))); } } // VALIDA EMPRESAS $rs_data = validaEmpresaUsuario($user_id, $empresa, false); if ($rs_data === false) { return $res->withStatus(400)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(400, 'ERR_DATABASE', 'Error al consultar la base de datos.'))); } else { $data_rows = intval(count($rs_data)); if ($data_rows > 0) { //$user_data = $rs_data[0]; //$user_id = $user_data['id']; # Nothing To-Do } else { return $res->withStatus(400)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(400, '', '', null))); } } if (intval($id) <= 0) { $res->withStatus(403)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(403, 1, UPDATE_ID_LOST, null))); } $sql = "UPDATE productos SET nombre=?,descripcion=?,sku_owner=?,sku_provider=?,id_unidad=?,existencia=?,existencia_min=?,imagen=?,updatedAt=? WHERE idx=? AND idx_empresa=?;"; try { if ($db === false) { throw new customException(HNDLR_CNXNDB); } $resp['id'] = null; $tmpArr = array($nombre, $descripcion, $sku_owner, $sku_provider, $unidad, $existencia, $existencia_min, $imagen, $date_current, $id, $empresa); $updated = $db->query($sql, $tmpArr); if ($updated !== false) { $tmpArrz = array($id, $proveedor, $precio, "16", $date_current); $sqlz = "INSERT INTO productos_history (idx_producto,idx_proveedor,precio,iva,createdAt) VALUES (?, ?, ?, ?, ?);"; $rows = $db->query($sqlz, $tmpArrz); $resp['id'] = $id; } $db->disconnect(); $db = null; $res->withStatus(200)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(200, 0, '', $resp))); } catch (PDOException $e) { $res->withStatus(400)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(400, 1, $e->getMessage(), null))); } catch (customException $e) { $res->withStatus(400)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(400, 3, $e->errorMessage(), null))); } catch (Exception $e) { $res->withStatus(400)->withHeader('Content-Type', 'application/json')->write(json_encode(responseHandler(400, 2, $e->getMessage(), null))); } }