All files / utils RecommendationRequestUtils.js

100% Statements 17/17
100% Branches 6/6
100% Functions 5/5
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58        4x 4x       9x   9x 2x         7x 3x         4x 3x           1x       5x 650x 650x 650x       17x 17x       9x                      
import { toast } from "react-toastify";
import { hasRole } from "main/utils/currentUser";
 
export function onDeleteSuccess(message) {
  console.log(message);
  toast(message);
}
 
export function cellToAxiosParamsDelete(cell, currentUser) {
  const { requester, professor, id } = cell.row.original;
 
  if (hasRole(currentUser, "ROLE_ADMIN")) {
    return {
      url: "/api/recommendationrequest/admin",
      method: "DELETE",
      params: { id },
    };
  } else if (requester.id === currentUser.root.user.id) {
    return {
      url: "/api/recommendationrequest",
      method: "DELETE",
      params: { id },
    };
  } else if (professor.id === currentUser.root.user.id) {
    return {
      url: "/api/recommendationrequest/professor",
      method: "DELETE",
      params: { id },
    };
  } else {
    throw new Error("Not authorized to delete this request");
  }
}
 
export const formattedDate = (val) => {
  const date = new Date(val);
  const formattedDate = `${String(date.getMonth() + 1).padStart(2, "0")}/${String(date.getDate()).padStart(2, "0")}/${date.getFullYear()} ${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
  return formattedDate;
};
 
export function onUpdateStatusSuccess(message) {
  console.log(message);
  toast(message);
}
 
export function cellToAxiosParamsUpdateStatus(cell, newStatus) {
  return {
    url: "/api/recommendationrequest/professor",
    method: "PUT",
    params: {
      id: cell.row.values.id,
    },
    data: {
      status: newStatus,
    },
  };
}