FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

  1. "use server";
  2. import { serverFetchJson } from "@/app/utils/fetchUtil";
  3. import { Machine, Operator } from ".";
  4. import { BASE_API_URL } from "@/config/api";
  5. import { revalidateTag } from "next/cache";
  6. export interface IsOperatorExistResponse<T> {
  7. id: number | null;
  8. name: string;
  9. code: string;
  10. type?: string;
  11. message: string | null;
  12. errorPosition: string | keyof T;
  13. entity: T;
  14. }
  15. export interface isCorrectMachineUsedResponse<T> {
  16. id: number | null;
  17. name: string;
  18. code: string;
  19. type?: string;
  20. message: string | null;
  21. errorPosition: string | keyof T;
  22. entity: T;
  23. }
  24. export const isOperatorExist = async (username: string) => {
  25. const isExist = await serverFetchJson<IsOperatorExistResponse<Operator>>(
  26. `${BASE_API_URL}/jop/isOperatorExist`,
  27. {
  28. method: "POST",
  29. body: JSON.stringify({ username }),
  30. headers: { "Content-Type": "application/json" },
  31. },
  32. );
  33. revalidateTag("po");
  34. return isExist;
  35. };
  36. export const isCorrectMachineUsed = async (machineCode: string) => {
  37. const isExist = await serverFetchJson<isCorrectMachineUsedResponse<Machine>>(
  38. `${BASE_API_URL}/jop/isCorrectMachineUsed`,
  39. {
  40. method: "POST",
  41. body: JSON.stringify({ machineCode }),
  42. headers: { "Content-Type": "application/json" },
  43. },
  44. );
  45. revalidateTag("po");
  46. return isExist;
  47. };