sanksi.js 968 B

123456789101112131415161718192021222324252627282930
  1. import { addLog } from "./log";
  2. export const createSanksi = async ({ number, ptId }, data) => {
  3. try {
  4. const res = await fetch(`http://localhost:5000/sanksi/create?number=${number}&ptId=${ptId}`, {
  5. method: "POST",
  6. body: data,
  7. });
  8. const result = await res.json();
  9. console.log(result);
  10. // addLog({ status: "SUCCESS", action: "CREATE", from: { id: result.added._id, data: "sanksi" }, description: "membuat sanksi" });
  11. return result;
  12. } catch (error) {
  13. console.log("error", error);
  14. addLog({ status: "FAIL", action: "CREATE", from: { data: "sanksi" }, description: error.message || "membuat sanksi" });
  15. return false;
  16. }
  17. };
  18. export const getSanksi = async (query = {}) => {
  19. try {
  20. let url = "http://localhost:5000/sanksi";
  21. if (query.ptId && query.noSanksi) url += `?noSanksi=${query.noSanksi}&ptId=${query.ptId}`;
  22. const res = await fetch(url);
  23. return await res.json();
  24. } catch (error) {
  25. console.log("error", error);
  26. return false;
  27. }
  28. };