pelaporan.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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) url += `?number=${query.number}&ptId=${query.ptId}`;
  6. if (query.penjadwalan) url += "?penjadwalan=true";
  7. if (query.pemeriksaan) url += "?pemeriksaan=true";
  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. addLog({ status: "FAIL", action: "CREATE", from: { data: "pelaporan" }, description: error.message || "membuat laporan" });
  26. return false;
  27. }
  28. };
  29. export const addStatus = async ({ number, ptId }, data) => {
  30. try {
  31. const myHeaders = new Headers();
  32. myHeaders.append("Content-Type", "application/json");
  33. const raw = JSON.stringify(data);
  34. const res = await fetch(`http://localhost:5000/pelaporan/status/add?number=${number}&ptId=${ptId}`, {
  35. method: "POST",
  36. body: raw,
  37. headers: myHeaders,
  38. });
  39. return await res.json();
  40. } catch (error) {
  41. return false;
  42. }
  43. };