log.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import axios from "@/config/axios";
  2. import axios2 from "axios";
  3. export const getLog = async (token, laporan_id) => {
  4. try {
  5. let url = `/pemantauan/${laporan_id}?all=true`;
  6. const res = await axios.get(url, {
  7. headers: {
  8. Authorization: token,
  9. },
  10. });
  11. return res.data;
  12. } catch (error) {
  13. console.log("error", error);
  14. return false;
  15. }
  16. };
  17. export const getLogPT = async (token) => {
  18. try {
  19. let url = `/pemantauan/pt`;
  20. const res = await axios.get(url, {
  21. headers: {
  22. Authorization: token,
  23. },
  24. });
  25. return res.data;
  26. } catch (error) {
  27. console.log("error", error);
  28. return false;
  29. }
  30. };
  31. export const getLogPublic = async ({ no_hp, no_laporan }) => {
  32. try {
  33. const res = await axios.get(`/public/pemantauan?no_hp=${no_hp}&no_laporan=${no_laporan}`);
  34. return res.data;
  35. } catch (error) {
  36. console.log("error", error);
  37. return false;
  38. }
  39. };
  40. export const createLog = async (token, data) => {
  41. try {
  42. const jsonip = await axios2.get("https://jsonip.com", { mode: "cors" });
  43. const res = await axios.post("/log", { os: navigator.userAgentData.platform, ipv4: jsonip.data.ip, ...data }, { headers: { Authorization: token } });
  44. return res.data;
  45. } catch (error) {
  46. console.log("error", error);
  47. return false;
  48. }
  49. };
  50. export const getLog2 = async (token, query = {}) => {
  51. try {
  52. let url = "/log";
  53. if (query != null) {
  54. const { fromDate, toDate } = query;
  55. url += "?";
  56. const parseURL = [];
  57. if (fromDate) {
  58. parseURL.push(`from_date=${fromDate}`);
  59. }
  60. if (toDate) {
  61. parseURL.push(`to_date=${toDate}`);
  62. }
  63. url += parseURL.join("&")
  64. }
  65. const res = await axios.get(url, { headers: { Authorization: token } });
  66. return res.data
  67. } catch (error) {
  68. console.log("error", error);
  69. return false;
  70. }
  71. };