From 6137fcc5a1b13528bf6a74c70abfc69663f84a61 Mon Sep 17 00:00:00 2001
From: Erik Borgeteien Hansen <erik@erikbhan.no>
Date: Tue, 3 May 2022 09:17:07 +0200
Subject: [PATCH] add api calls to service

---
 src/services/community-admin.service.js | 49 ++++++++++++++++---------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/src/services/community-admin.service.js b/src/services/community-admin.service.js
index 81f1581..af9b685 100644
--- a/src/services/community-admin.service.js
+++ b/src/services/community-admin.service.js
@@ -7,41 +7,54 @@ const API_URL = process.env.VUE_APP_BASEURL;
  * Service class acting as a middle layer between our components and the API
  */
 class CommunityAdminService {
-  async isUserAdmin() {
+  async isUserAdmin(communityID) {
     return await axios
-      .get(
-        API_URL +
-          "communities/" +
-          this.$route.params.communityID +
-          "/user/admin",
-        {
-          headers: tokenHeader(),
-        }
-      )
+      .get(API_URL + "communities/" + communityID + "/user/admin", {
+        headers: tokenHeader(),
+      })
       .then((res) => {
         return res.data;
       });
   }
 
   //TODO
-  acceptUserIntoCommunity() {}
+  async acceptUserIntoCommunity(communityID, userID) {
+    return await axios.post(
+      API_URL + "communities/" + communityID + "/requests",
+      { params: { userId: userID } }
+    );
+  }
 
   //TODO
-  rejectUserFromCommunity() {}
+  async rejectUserFromCommunity(communityID, userID) {
+    return await axios.patch(
+      API_URL + "communitites/" + communityID + "/requests/reject",
+      {
+        params: { userId: userID },
+      }
+    );
+  }
 
-  //TODO
-  async removeUserFromCommunity(user, community) {
-    return await axios.post(API_URL + "communities/" + community.id + "/leave");
+  /**
+   * Method that kicks a user from a community
+   * @param {int} communityID the community to remove the user from
+   * @param {int} userID the user to remove
+   * @returns TODO
+   */
+  async removeUserFromCommunity(communityID, userID) {
+    return await axios.patch(API_URL + "communities/" + communityID + "/kick", {
+      params: { userId: userID },
+    });
   }
 
   /**
    * Method to delete a community
-   * @param {int} communityId id of the community to delete.
+   * @param {int} communityID id of the community to delete.
    * @returns TODO
    */
-  async deleteCommunity(communityId) {
+  async deleteCommunity(communityID) {
     return await axios.post(
-      API_URL + "communities/" + communityId + "/remove",
+      API_URL + "communities/" + communityID + "/remove",
       {
         headers: tokenHeader(),
       }
-- 
GitLab