Skip to content
Snippets Groups Projects
user.service.js 3.06 KiB
Newer Older
import { tokenHeader } from "@/utils/token-utils";
import axios from "axios";

const API_URL = process.env.VUE_APP_BASEURL;

class UserService {
  async getUserFromId(userId) {
    return await axios
      .get(API_URL + "users/" + userId + "/profile", {
        headers: tokenHeader(),
      })
      .then((res) => {
        return res.data;
      })
      .catch((err) => console.error(err));
  }
  async getAdminList() {
    return await axios
Erik Borgeteien Hansen's avatar
Erik Borgeteien Hansen committed
      .get(API_URL + "communities/admin", {
        headers: tokenHeader(),
      })
      .then((res) => {
        return res.data;
      })
      .catch((err) => {
        console.error(err);
      });
  }

  async getUserRatingAverage(userId) {
    return await axios
      .get(API_URL + "rating/" + userId + "/average", {
        headers: tokenHeader(),
      })
      .then((res) => {
        return res.data;
      })
      .catch((err) => console.error(err));
  }
  async setListingToDeleted(listingId) {
    return await axios
      .delete(API_URL + "listing/" + listingId, {
      })
      .then((res) => {
        return res.data;
      })
henrikburmann's avatar
henrikburmann committed
      .catch((err) => {
henrikburmann's avatar
henrikburmann committed

  async getRenterHistory() {
Gilgard's avatar
Gilgard committed
    return await axios
      .get(API_URL + "user/profile/rent/history", {
Gilgard's avatar
Gilgard committed
        headers: tokenHeader(),
      })
      .then((res) => {
        return res.data;
      })
Gilgard's avatar
Gilgard committed
      .catch((err) => {
        console.error(err);
        return [];
      });
Gilgard's avatar
Gilgard committed
  }
Gilgard's avatar
Gilgard committed
  async getOwnerHistory() {
    return await axios
Gilgard's avatar
Gilgard committed
      .get(API_URL + "user/profile/rent/history/owner", {
        headers: tokenHeader(),
      })
      .then((res) => {
        return res.data;
      })
Gilgard's avatar
Gilgard committed
      .catch((err) => {
        console.error(err);
      });
Gilgard's avatar
Gilgard committed
  async isRated(rentID) {
    return await axios
Gilgard's avatar
Gilgard committed
      .get(API_URL + "rating/" + rentID + "/israted", {
        headers: tokenHeader(),
      })
      .then((res) => {
        return res.data;
      })
Gilgard's avatar
Gilgard committed
      .catch((err) => {
        console.error(err);
      });
Gilgard's avatar
Gilgard committed

henrikburmann's avatar
henrikburmann committed
  async getUserRatingAsRenter(userId) {
    return await axios
      .get(API_URL + "rating/" + userId + "/average/renter", {
        headers: tokenHeader(),
      })
      .then((res) => {
        return res.data;
      })
      .catch((err) => console.error(err));
  }

  async getUserRatingAsOwner(userId) {
    return await axios
henrikburmann's avatar
henrikburmann committed
      .get(API_URL + "rating/" + userId + "/average/owner", {
        headers: tokenHeader(),
      })
      .then((res) => {
        return res.data;
      })
      .catch((err) => console.error(err));
henrikburmann's avatar
henrikburmann committed

  async deleteUser() {
henrikburmann's avatar
henrikburmann committed
    return await axios
      .delete(API_URL + "user/delete", {
        headers: tokenHeader(),
      })
      .then((res) => {
        return res.data;
      })
      .catch((err) => console.log(err));
henrikburmann's avatar
henrikburmann committed
  }

  async registerUser(userInfo) {
    return await axios
      .post(API_URL + "register", userInfo)
      .then((res) => {
        return res;
      })
      .catch((err) => {
        if (err.response) {
          return err.response.data;
        }
        console.error(err);
      });
  }
export default new UserService();