pengunjung.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import axios from "@/config/axios";
  2. import axios2 from "axios";
  3. export const createPengunjung = async (_csrf) => {
  4. try {
  5. const jsonip = await axios2.get("https://ip-api.io/json");
  6. const res = await axios.post(`/pengunjung/create?_csrf=${_csrf}`, {
  7. os: navigator.userAgentData.platform,
  8. ipv4: jsonip.data.ip,
  9. location: {
  10. country: jsonip.data.country_name,
  11. region: jsonip.data.region_name,
  12. city: jsonip.data.city,
  13. lat: jsonip.data.latitude,
  14. lon: jsonip.data.longitude,
  15. timezone: jsonip.data.time_zone,
  16. },
  17. });
  18. return res.data;
  19. } catch (error) {
  20. console.log("error", error);
  21. return false;
  22. }
  23. };
  24. export const getPengunjung = async (token) => {
  25. try {
  26. const res = await axios.get(`/pengunjung?tahun=${new Date().getFullYear()}`, { headers: { Authorization: token } });
  27. return res.data;
  28. } catch (error) {
  29. console.log("error", error);
  30. return false;
  31. }
  32. };
  33. export const getPengunjungPublic = async ({ bulan, tahun }) => {
  34. try {
  35. let url = "/public/pengunjung";
  36. if (bulan || tahun) {
  37. url += "?";
  38. const parseURL = [];
  39. if (bulan) {
  40. parseURL.push(`bulan=${bulan}`);
  41. }
  42. if (tahun) {
  43. parseURL.push(`tahun=${tahun}`);
  44. }
  45. url += parseURL.join("&");
  46. }
  47. const res = await axios.get(url);
  48. return res.data;
  49. } catch (error) {
  50. console.log("error", error);
  51. return false;
  52. }
  53. };