pelaporan.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { addLog } from "./log";
  2. export const getPelaporan = async (query = {}) => {
  3. try {
  4. let url = "http://localhost:5000/pelaporan";
  5. if (query.ptId && query.number) {
  6. url += `?number=${query.number}&ptId=${query.ptId}`;
  7. }
  8. const res = await fetch(url);
  9. return await res.json();
  10. } catch (error) {
  11. console.log("error", error);
  12. return false;
  13. }
  14. };
  15. export const createPelaporan = async (data) => {
  16. try {
  17. const res = await fetch("http://localhost:5000/pelaporan/create", {
  18. method: "POST",
  19. body: data,
  20. });
  21. const result = await res.json();
  22. addLog({ status: "SUCCESS", action: "CREATE", from: { id: result.created._id, data: "pelaporan" }, description: "membuat laporan" });
  23. return result;
  24. } catch (error) {
  25. console.log("error", error);
  26. addLog({ status: "FAIL", action: "CREATE", from: { data: "pelaporan" }, description: error.message || "membuat laporan" });
  27. return false;
  28. }
  29. };
  30. export const addStatus = async ({ number, ptId }, data) => {
  31. try {
  32. const myHeaders = new Headers();
  33. myHeaders.append("Content-Type", "application/json");
  34. const raw = JSON.stringify(data);
  35. const res = await fetch(`http://localhost:5000/pelaporan/status/add?number=${number}&ptId=${ptId}`, {
  36. method: "POST",
  37. body: raw,
  38. headers: myHeaders,
  39. });
  40. return await res.json();
  41. } catch (error) {
  42. console.log("error", error);
  43. return false;
  44. }
  45. };