pelaporan.js 2.9 KB

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