|
- "use server";
- import { serverFetchJson } from "@/app/utils/fetchUtil";
- import { Machine, Operator } from ".";
- import { BASE_API_URL } from "@/config/api";
- import { revalidateTag } from "next/cache";
-
- export interface IsOperatorExistResponse<T> {
- id: number | null;
- name: string;
- code: string;
- type?: string;
- message: string | null;
- errorPosition: string | keyof T;
- entity: T;
- }
-
- export interface isCorrectMachineUsedResponse<T> {
- id: number | null;
- name: string;
- code: string;
- type?: string;
- message: string | null;
- errorPosition: string | keyof T;
- entity: T;
- }
-
- export const isOperatorExist = async (username: string) => {
- const isExist = await serverFetchJson<IsOperatorExistResponse<Operator>>(
- `${BASE_API_URL}/jop/isOperatorExist`,
- {
- method: "POST",
- body: JSON.stringify({ username }),
- headers: { "Content-Type": "application/json" },
- },
- );
- revalidateTag("po");
- return isExist;
- };
-
- export const isCorrectMachineUsed = async (machineCode: string) => {
- const isExist = await serverFetchJson<isCorrectMachineUsedResponse<Machine>>(
- `${BASE_API_URL}/jop/isCorrectMachineUsed`,
- {
- method: "POST",
- body: JSON.stringify({ machineCode }),
- headers: { "Content-Type": "application/json" },
- },
- );
- revalidateTag("po");
- return isExist;
- };
|