OMEGA\ericyh.huang 1 year ago
parent
commit
b5975bf9ca
2 changed files with 18 additions and 0 deletions
  1. 17
    0
      src/be/app/Http/Controllers/HealthyPassPortController.php
  2. 1
    0
      src/be/routes/api.php

+ 17
- 0
src/be/app/Http/Controllers/HealthyPassPortController.php View File

@@ -106,6 +106,23 @@ class HealthyPassPortController extends Controller
106 106
             return response()->json(["result" => 'failed'] );
107 107
         }
108 108
     }
109
+    public function clearProfile(Request $request){
110
+        $lineUserId = $request->lineUserId; //line UID
111
+        $survey_data = Survey::where('line_user_id',$lineUserId)->first();
112
+        if(!empty($survey_data->id)){
113
+            $filler_content = json_decode($survey_data->filler_content, true);
114
+            $clearAction = [];
115
+            foreach($filler_content as $key => $content){
116
+                array_push($clearAction, $this->buildActionsRequest("removeTag", $content));
117
+            }
118
+            array_push($clearAction, $this->buildActionsRequest("removeTag", config("botApi.doneSurvey")));
119
+            array_push($clearAction, $this->buildActionsRequest("setMenu", "default"));
120
+            $statusCode = $this->botActionsSend($lineUserId,$clearAction);
121
+            if($statusCode == 200){
122
+                $survey_data->delete();
123
+            }
124
+        }
125
+    }
109 126
 
110 127
     function buildActionsRequest($type, $values, $groupId = null, $paramName = ""){
111 128
         if($type == "addTag" || $type == "removeTag"){

+ 1
- 0
src/be/routes/api.php View File

@@ -24,6 +24,7 @@ Route::prefix('survey')->group(function () {
24 24
         Route::get('/profile', [HealthyPassPortController::class, 'profile']);
25 25
         Route::post('/post', [HealthyPassPortController::class, 'post']);
26 26
         Route::post('/stickerUpdate', [HealthyPassPortController::class, 'sticker']);
27
+        Route::post('/clearProfile', [HealthyPassPortController::class, 'clearProfile']);
27 28
     });
28 29
 });
29 30