From cb6d49de2bfd87d063619d673f8f019f3cce2094 Mon Sep 17 00:00:00 2001 From: SaktiWidyatmaja <saktiwidyatmaja1@gmail.com> Date: Thu, 16 Nov 2023 21:01:02 +0700 Subject: [PATCH] feat: add updateUserPremiumStatsu --- app/api/premium/updateUserPremiumStatus.php | 40 +++++++++++++++++++++ public/js/assess.js | 20 +++++++---- 2 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 app/api/premium/updateUserPremiumStatus.php diff --git a/app/api/premium/updateUserPremiumStatus.php b/app/api/premium/updateUserPremiumStatus.php new file mode 100644 index 0000000..4cf0cbf --- /dev/null +++ b/app/api/premium/updateUserPremiumStatus.php @@ -0,0 +1,40 @@ +<?php + +require_once __DIR__ . '/../../../config/config.php'; + +if (isset($_ENV['SOAP_URL'])) { + $url = $_ENV['SOAP_URL']; +} else if (isset($_ENV['SOLO_DOCKER'])) { + $url = "http://host.docker.internal:8888/ws/subscription"; +} else { + $url = "http://localhost:8888/ws/subscription"; +} + +$id = $_POST['user_id']; + +$request_body = json_encode(array('user_id' => $id)); + +$headers = array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($request_body), + 'X-API-Key: ' . $_ENV['SOAP_API_KEY'] +); + +$ch = curl_init(); +curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); +curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); +curl_setopt($ch, CURLOPT_POSTFIELDS, $request_body); +curl_setopt($ch, CURLOPT_URL, 'http://localhost:3000/api/update-user'); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + +$response = curl_exec($ch); +curl_close($ch); + +if ($response === FALSE) { + printf("CURL error (#%d): %s<br>\n", curl_errno($ch), + htmlspecialchars(curl_error($ch))); +} + +http_response_code(200); +echo $response; +?> diff --git a/public/js/assess.js b/public/js/assess.js index f6172ba..40a3c2e 100644 --- a/public/js/assess.js +++ b/public/js/assess.js @@ -59,27 +59,35 @@ const acceptRequest = (userId) => { if (response.includes("Request accepted")) { alert("Request accepted"); - // Arahkan pengguna ke URL /notes + + const updateUserPremiumStatusXHR = new XMLHttpRequest(); + updateUserPremiumStatusXHR.open("POST", "../../app/api/premium/updateUserPremiumStatus.php", true); + updateUserPremiumStatusXHR.onload = function() { + if (updateUserPremiumStatusXHR.readyState == 4 && updateUserPremiumStatusXHR.status == 200) { + console.log("User premium status updated"); + } else { + console.error("Failed to update user premium status"); + } + }; + updateUserPremiumStatusXHR.send(data); + window.location.href = "/?admin/assess"; } else if (response.includes("Request already accepted")) { alert("Request already accepted"); - // Lakukan tindakan tambahan jika diperlukan } else if (response.includes("Request already rejected")) { alert("Request already rejected"); - // Lakukan tindakan tambahan jika diperlukan } else if (response.includes("Request not found")) { alert("Request not found"); - // Lakukan tindakan tambahan jika diperlukan } else { alert("Failed to accept request"); } } else { alert("Failed to accept request"); } - } + }; xhr.send(data); -} +}; const rejectRequest = (userId) => { const data = new FormData(); -- GitLab