pengunjung.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import axios from "@/config/axios";
  2. import axios2 from "axios";
  3. export const createPengunjung = async () => {
  4. try {
  5. const jsonip = await axios2.get("http://ip-api.com/json");
  6. const res = await axios.post("/pengunjung/create", {
  7. os: navigator.userAgentData.platform,
  8. ipv4: jsonip.data.query,
  9. location: {
  10. ...jsonip.data,
  11. region: jsonip.data.regionName,
  12. },
  13. });
  14. return res.data;
  15. } catch (error) {
  16. console.log("error", error);
  17. return false;
  18. }
  19. };
  20. export const getPengunjung = async (token) => {
  21. try {
  22. const res = await axios.get(`/pengunjung`, { headers: { Authorization: token } });
  23. return res.data;
  24. } catch (error) {
  25. console.log("error", error);
  26. return false;
  27. }
  28. };
  29. export const getPengunjungPublic = async ({ bulan, tahun }) => {
  30. try {
  31. let url = "/public/pengunjung";
  32. if (bulan || tahun) {
  33. url += "?";
  34. if (bulan) {
  35. url += `bulan=${bulan}`;
  36. }
  37. if (tahun) {
  38. url += `bulan=${tahun}`;
  39. }
  40. }
  41. const res = await axios.get(url);
  42. return res.data;
  43. } catch (error) {
  44. console.log("error", error);
  45. return false;
  46. }
  47. };