pelaporan.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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, aktif } = 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. if (aktif === false) {
  22. parseURL.push(`aktif=false`);
  23. }
  24. url += parseURL.join("&");
  25. }
  26. const res = await axiosAPI.get(url, { headers: { Authorization: token } });
  27. return res.data;
  28. } catch (error) {
  29. console.log("error", error);
  30. return false;
  31. }
  32. };
  33. export const getOneLaporan = async (token, id, query = {}) => {
  34. try {
  35. let url = `/laporan/${id}`;
  36. if (query != null) {
  37. const { aktif } = query;
  38. url += "?";
  39. const parseURL = [];
  40. if (aktif === false) {
  41. parseURL.push(`aktif=false`);
  42. }
  43. url += parseURL.join("&");
  44. }
  45. const res = await axiosAPI.get(url, { headers: { Authorization: token } });
  46. return res.data;
  47. } catch (error) {
  48. console.log("error", error);
  49. return false;
  50. }
  51. };
  52. export const getPelaporanPublic = async ({ number, noHp }) => {
  53. try {
  54. const res = await get(`/pelaporan/public?number=${number}&noHp=${noHp}`);
  55. return res.data;
  56. } catch (error) {
  57. console.log("error", error.response.data);
  58. return false;
  59. }
  60. };
  61. export const createPelaporan = async (token, data) => {
  62. const res = await axiosAPI.post("/laporan/create", data, { headers: { Authorization: token } });
  63. await createLog(token, { aktivitas: "Berhasil Membuat pelaporan" });
  64. return res.data;
  65. };
  66. // export const createLaporanPublic = async (data) => {
  67. // try {
  68. // const res = await axiosAPI.post("/public/laporan/create", data);
  69. // return res.data;
  70. // } catch (error) {
  71. // console.log("error", error.response.data);
  72. // return false;
  73. // }
  74. // };
  75. export const createLaporanPublic = async (token, data) => {
  76. try {
  77. const res = await axiosAPI.post("/public/laporan/create", data, { headers: { Authorization: token } });
  78. return res.data;
  79. } catch (error) {
  80. console.log("error", error.response.data);
  81. return false;
  82. }
  83. };
  84. // export const addStatus = async ({ number, ptId }, data) => {
  85. // try {
  86. // const res = await post(`/pelaporan/status/add?number=${number}&ptId=${ptId}`, data);
  87. // return res.data;
  88. // } catch (error) {
  89. // console.log("error", error);
  90. // return false;
  91. // }
  92. // };
  93. export const updateLaporan = async (token, id, data) => {
  94. try {
  95. const res = await axiosAPI.put(`/laporan/update/${id}`, data, { headers: { Authorization: token } });
  96. if (data.aktif === "false") await createLog(token, { aktivitas: `Berhasil menutup laporan, id: ${id}` });
  97. await createLog(token, { aktivitas: `Berhasil mengubah data laporan, id: ${id}` });
  98. return res.data;
  99. } catch (error) {
  100. console.log("error", error.response.data);
  101. await createLog(token, { aktivitas: `Gagal mengubah data pelaporan, id: ${id}` });
  102. return false;
  103. }
  104. };
  105. export const jumlahLaporan = async (token) => {
  106. try {
  107. const res = await axiosAPI.get(`/laporan/jumlah`, { headers: { Authorization: token } });
  108. return res.data;
  109. } catch (error) {
  110. console.log("error", error.response.data);
  111. return false;
  112. }
  113. };
  114. // export const activeLaporan = async ({ number, ptId }) => {
  115. // try {
  116. // const res = await put(`/pelaporan/active?number=${number}&ptId=${ptId}`);
  117. // return res.data;
  118. // } catch (error) {
  119. // console.log("error", error);
  120. // return false;
  121. // }
  122. // };
  123. // export const changeRoleData = async ({ number, ptId }, data) => {
  124. // try {
  125. // const res = await post(`/pelaporan/change-role-data?number=${number}&ptId=${ptId}`, data);
  126. // return res.data;
  127. // } catch (error) {
  128. // console.log("error", error);
  129. // return false;
  130. // }
  131. // };