diff --git a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php index 9b8a11c..26673ac 100644 --- a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php +++ b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php @@ -28,6 +28,10 @@ class Wiass_REST_Delivery_Process_API { 'callback' => array(__CLASS__, 'get_customer_acceptance'), ) ); + /* + + Used for some fast test and check + register_rest_route( self::$namespace, 'gravity-form-entry/(?P\d+)', array( 'methods' => 'GET', 'callback' => array(__CLASS__, 'get_form_entry'), @@ -43,6 +47,8 @@ class Wiass_REST_Delivery_Process_API { 'callback' => array(__CLASS__, 'update_entry'), ) ); + */ + register_rest_route( self::$namespace, 'customer-acceptance/(?P\d+)', array( 'methods' => 'POST', 'callback' => array(__CLASS__, 'update_customer_acceptance'), @@ -101,13 +107,9 @@ class Wiass_REST_Delivery_Process_API { return $response; } - public static function get_form_entry($data) { - //TODO: check for permissions - return GFAPI::get_entry($data['entry_id']); - } - public static function get_customer_acceptance($data){ //TODO: check for permissions + $entry = GFAPI::get_entry($data['entry_id']); if (!$entry){ return self::generate_error('Customer acceptance entry not found', 404); @@ -128,7 +130,7 @@ class Wiass_REST_Delivery_Process_API { $acceptance_status = 0; if ($entry[self::$ACCEPTANCE_STATUS_FIELD_ID]){ - $acceptance_status = ($entry[self::$ACCEPTANCE_STATUS_FIELD_ID] == 'accept') ? 1 : -1; + $acceptance_status = ($entry[self::$ACCEPTANCE_STATUS_FIELD_ID] === 'accept') ? 1 : -1; } $result = array( @@ -141,28 +143,6 @@ class Wiass_REST_Delivery_Process_API { return new WP_REST_Response($result); } - public static function get_field_value_from_entry($data){ - //TODO : check for permissions - $entry = GFAPI::get_entry($data['entry_id']); - $result = $entry[$data['field_id']] ?: ''; - return new WP_REST_Response ($result); - } - - public static function update_entry($data){ - //TODO : check for permissions - $entry = GFAPI::get_entry($data['entry_id']); - $new_values = json_decode($data->get_body()); - if ($new_values == NULL) { - return new WP_REST_Response (); - } - $keys = get_object_vars($new_values); - foreach($keys as $key => $value){ - $entry[$key] = $value; - } - $result = GFAPI::update_entry( $entry ); - return new WP_REST_Response ($result); - } - public static function update_customer_acceptance($data){ //TODO : check for permissions $entry = GFAPI::get_entry($data['entry_id']); @@ -231,7 +211,7 @@ class Wiass_REST_Delivery_Process_API { $uploaded_files = json_decode($entry[self::$UPLOADED_FILES_FIELD_ID]); - if ($uploaded_files == NULL){ + if ($uploaded_files === NULL){ $uploaded_files = []; } array_push($uploaded_files, $file_url); @@ -245,7 +225,40 @@ class Wiass_REST_Delivery_Process_API { return self::generate_error('Error updating entry'); } - public static function generate_error($message, $code = 500){ + //Used for testing and checking + /* + public static function get_form_entry($data) { + //TODO: check for permissions + return GFAPI::get_entry($data['entry_id']); + } + + public static function get_field_value_from_entry($data){ + //TODO : check for permissions + $entry = GFAPI::get_entry($data['entry_id']); + $result = $entry[$data['field_id']] ?: ''; + return new WP_REST_Response ($result); + } + + public static function update_entry($data){ + //TODO : check for permissions + $entry = GFAPI::get_entry($data['entry_id']); + $new_values = json_decode($data->get_body()); + if ($new_values === NULL) { + return new WP_REST_Response (); + } + $keys = get_object_vars($new_values); + foreach($keys as $key => $value){ + $entry[$key] = $value; + } + $result = GFAPI::update_entry( $entry ); + return new WP_REST_Response ($result); + } + + */ + + + //Helper function + private static function generate_error($message, $code = 500){ $error = array( 'status' => $code, 'message' => $message,