FPSMS-frontend
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

108 wiersze
2.5 KiB

  1. "use server";
  2. import { cache } from 'react';
  3. import { Pageable, serverFetchJson } from "@/app/utils/fetchUtil";
  4. import { Machine, Operator } from ".";
  5. import { BASE_API_URL } from "@/config/api";
  6. import { revalidateTag } from "next/cache";
  7. import { convertObjToURLSearchParams } from "@/app/utils/commonUtil";
  8. export interface SearchJoResultRequest extends Pageable {
  9. code: string;
  10. name: string;
  11. }
  12. export interface SearchJoResultResponse {
  13. records: SearchJoResult[];
  14. total: number;
  15. }
  16. export interface SearchJoResult {
  17. id: number;
  18. code: string;
  19. name: string;
  20. reqQty: number;
  21. uom: string;
  22. status: string;
  23. }
  24. export interface ReleaseJoRequest {
  25. id: number;
  26. }
  27. export interface ReleaseJoResponse {
  28. id: number;
  29. entity: { status: string }
  30. }
  31. export interface IsOperatorExistResponse<T> {
  32. id: number | null;
  33. name: string;
  34. code: string;
  35. type?: string;
  36. message: string | null;
  37. errorPosition: string | keyof T;
  38. entity: T;
  39. }
  40. export interface isCorrectMachineUsedResponse<T> {
  41. id: number | null;
  42. name: string;
  43. code: string;
  44. type?: string;
  45. message: string | null;
  46. errorPosition: string | keyof T;
  47. entity: T;
  48. }
  49. export const isOperatorExist = async (username: string) => {
  50. const isExist = await serverFetchJson<IsOperatorExistResponse<Operator>>(
  51. `${BASE_API_URL}/jop/isOperatorExist`,
  52. {
  53. method: "POST",
  54. body: JSON.stringify({ username }),
  55. headers: { "Content-Type": "application/json" },
  56. },
  57. );
  58. revalidateTag("po");
  59. return isExist;
  60. };
  61. export const isCorrectMachineUsed = async (machineCode: string) => {
  62. const isExist = await serverFetchJson<isCorrectMachineUsedResponse<Machine>>(
  63. `${BASE_API_URL}/jop/isCorrectMachineUsed`,
  64. {
  65. method: "POST",
  66. body: JSON.stringify({ machineCode }),
  67. headers: { "Content-Type": "application/json" },
  68. },
  69. );
  70. revalidateTag("po");
  71. return isExist;
  72. };
  73. export const fetchJos = cache(async (data?: SearchJoResultRequest) => {
  74. const queryStr = convertObjToURLSearchParams(data)
  75. const response = serverFetchJson<SearchJoResultResponse>(
  76. `${BASE_API_URL}/jo/getRecordByPage?${queryStr}`,
  77. {
  78. method: "GET",
  79. headers: { "Content-Type": "application/json" },
  80. next: {
  81. tags: ["jos"]
  82. }
  83. }
  84. )
  85. return response
  86. })
  87. export const releaseJo = cache(async (data: ReleaseJoRequest) => {
  88. return serverFetchJson<ReleaseJoResponse>(`${BASE_API_URL}/jo/release`,
  89. {
  90. method: "POST",
  91. body: JSON.stringify(data),
  92. headers: { "Content-Type": "application/json" },
  93. })
  94. })