"use server"; import { BASE_API_URL } from "@/config/api"; // import { ServerFetchError, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; import { revalidateTag } from "next/cache"; import { cache } from "react"; import { Pageable, serverFetchJson } from "@/app/utils/fetchUtil"; import { QcItemResult } from "../settings/qcItem"; import { RecordsRes } from "../utils"; import { convertObjToURLSearchParams } from "@/app/utils/commonUtil"; import { InventoryLotLineResult, InventoryResult } from "."; // import { BASE_API_URL } from "@/config/api"; export interface LotLineInfo { inventoryLotLineId: number; itemId: number; itemNo: string; itemName: string; lotNo: string; remainingQty: number; uom: string; } export interface SearchInventoryLotLine extends Pageable { itemId: number; } export interface SearchInventory extends Pageable { code: string; name: string; type: string; } export interface InventoryResultByPage { total: number; records: InventoryResult[]; } export interface UpdateInventoryLotLineStatusRequest { inventoryLotLineId: number; status: string; } export interface InventoryLotLineResultByPage { total: number; records: InventoryLotLineResult[]; } export interface PostInventoryLotLineResponse { id: number | null; name: string; code: string; type?: string; message: string | null; errorPosition: string entity?: T | T[]; consoCode?: string; } export const updateInventoryStatus = async (data: { itemId: number; lotId: number; status: string; qty: number; }) => { return serverFetchJson(`${BASE_API_URL}/inventory/update-status`, { method: 'PUT', body: JSON.stringify(data) }); }; export const fetchLotDetail = cache(async (stockInLineId: number) => { return serverFetchJson( `${BASE_API_URL}/inventoryLotLine/lot-detail/${stockInLineId}`, { method: "GET", next: { tags: ["inventory"] }, }, ); }); export const updateInventoryLotLineStatus = async (data: { inventoryLotLineId: number; status: string; qty: number; operation?: string; }) => { return serverFetchJson(`${BASE_API_URL}/inventory/lot-line/update-status`, { method: 'PUT', body: JSON.stringify(data) }); }; export const fetchInventories = cache(async (data: SearchInventory) => { const queryStr = convertObjToURLSearchParams(data) return serverFetchJson(`${BASE_API_URL}/inventory/getRecordByPage?${queryStr}`, { next: { tags: ["inventories"] } } ) }) export const fetchInventoryLotLines = cache(async (data: SearchInventoryLotLine) => { const queryStr = convertObjToURLSearchParams(data) return serverFetchJson(`${BASE_API_URL}/inventoryLotLine/getRecordByPage?${queryStr}`, { next: { tags: ["inventoryLotLines"] }, }); }); export const updateInventoryLotLineQuantities = async (data: { inventoryLotLineId: number; qty: number; operation: string; status: string; }) => { const result = await serverFetchJson( `${BASE_API_URL}/inventoryLotLine/updateQuantities`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }, ); revalidateTag("pickorder"); return result; };