pelaporan.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { get, post, del, put } from "../config/request";
  2. import axiosAPI from "../config/axios";
  3. import { createLog } from "./log";
  4. export const getPelaporan = async (token, query = {}) => {
  5. try {
  6. let url = "/laporan";
  7. if (query != null) {
  8. const { jadwal, evaluasi, pt_id, delegasi } = query;
  9. url += "?";
  10. const parseURL = [];
  11. if (jadwal) {
  12. parseURL.push(`jadwal=true`);
  13. } else if (evaluasi) {
  14. parseURL.push(`evaluasi=true`);
  15. } else if (delegasi) {
  16. parseURL.push(`delegasi=true`);
  17. }
  18. if (pt_id) {
  19. parseURL.push(`pt_id=${pt_id}`);
  20. }
  21. url += parseURL.join("&");
  22. }
  23. const res = await axiosAPI.get(url, { headers: { Authorization: token } });
  24. return res.data;
  25. } catch (error) {
  26. console.log("error", error);
  27. return false;
  28. }
  29. };
  30. export const getOneLaporan = async (token, id) => {
  31. try {
  32. const res = await axiosAPI.get(`/laporan/${id}`, { headers: { Authorization: token } });
  33. return res.data;
  34. } catch (error) {
  35. console.log("error", error);
  36. return false;
  37. }
  38. };
  39. export const getPelaporanPublic = async ({ number, noHp }) => {
  40. try {
  41. const res = await get(`/pelaporan/public?number=${number}&noHp=${noHp}`);
  42. return res.data;
  43. } catch (error) {
  44. console.log("error", error.response.data);
  45. return false;
  46. }
  47. };
  48. export const createPelaporan = async (token, data) => {
  49. const res = await axiosAPI.post("/laporan/create", data, { headers: { Authorization: token } });
  50. await createLog(token, { aktivitas: "Berhasil Membuat pelaporan" });
  51. return res.data;
  52. };
  53. // export const createLaporanPublic = async (data) => {
  54. // try {
  55. // const res = await axiosAPI.post("/public/laporan/create", data);
  56. // return res.data;
  57. // } catch (error) {
  58. // console.log("error", error.response.data);
  59. // return false;
  60. // }
  61. // };
  62. export const createLaporanPublic = async (token, data) => {
  63. try {
  64. const res = await axiosAPI.post("/public/laporan/create", data, { headers: { Authorization: token } });
  65. return res.data;
  66. } catch (error) {
  67. console.log("error", error.response.data);
  68. return false;
  69. }
  70. };
  71. // export const addStatus = async ({ number, ptId }, data) => {
  72. // try {
  73. // const res = await post(`/pelaporan/status/add?number=${number}&ptId=${ptId}`, data);
  74. // return res.data;
  75. // } catch (error) {
  76. // console.log("error", error);
  77. // return false;
  78. // }
  79. // };
  80. export const updateLaporan = async (token, id, data) => {
  81. try {
  82. const res = await axiosAPI.put(`/laporan/update/${id}`, data, { headers: { Authorization: token } });
  83. if (data.aktif === "false") await createLog(token, { aktivitas: `Berhasil menutup laporan, id: ${id}` });
  84. await createLog(token, { aktivitas: `Berhasil mengubah data laporan, id: ${id}` });
  85. return res.data;
  86. } catch (error) {
  87. console.log("error", error.response.data);
  88. await createLog(token, { aktivitas: `Gagal mengubah data pelaporan, id: ${id}` });
  89. return false;
  90. }
  91. };
  92. export const jumlahLaporan = async (token) => {
  93. try {
  94. const res = await axiosAPI.get(`/laporan/jumlah`, { headers: { Authorization: token } });
  95. return res.data;
  96. } catch (error) {
  97. console.log("error", error.response.data);
  98. return false;
  99. }
  100. };
  101. // export const activeLaporan = async ({ number, ptId }) => {
  102. // try {
  103. // const res = await put(`/pelaporan/active?number=${number}&ptId=${ptId}`);
  104. // return res.data;
  105. // } catch (error) {
  106. // console.log("error", error);
  107. // return false;
  108. // }
  109. // };
  110. // export const changeRoleData = async ({ number, ptId }, data) => {
  111. // try {
  112. // const res = await post(`/pelaporan/change-role-data?number=${number}&ptId=${ptId}`, data);
  113. // return res.data;
  114. // } catch (error) {
  115. // console.log("error", error);
  116. // return false;
  117. // }
  118. // };