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.
 
 

66 lines
1.8 KiB

  1. "use server";
  2. import { BASE_API_URL } from "@/config/api";
  3. // import { ServerFetchError, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  4. import { revalidateTag } from "next/cache";
  5. import { cache } from "react";
  6. import { PoResult, StockInLine } from ".";
  7. import { serverFetchJson } from "@/app/utils/fetchUtil";
  8. // import { BASE_API_URL } from "@/config/api";
  9. export interface PostStockInLiineResponse<T> {
  10. id: number | null;
  11. name: string;
  12. code: string;
  13. message: string | null;
  14. errorPosition: string | keyof T;
  15. entity: StockInLine | StockInLine[]
  16. }
  17. export interface StockInLineEntry {
  18. id?: number
  19. itemId: number
  20. purchaseOrderId: number
  21. purchaseOrderLineId: number
  22. acceptedQty: number
  23. status?: string
  24. }
  25. export interface PurchaseQcCheck {
  26. qcCheckId: number;
  27. qty: number;
  28. }
  29. export interface PurchaseQCInput {
  30. sampleRate: number;
  31. sampleWeight: number;
  32. totalWeight: number;
  33. qcCheck: PurchaseQcCheck[];
  34. }
  35. export const testFetch = cache(async (id: number) => {
  36. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  37. next: { tags: ["po"] },
  38. });
  39. });
  40. export const createStockInLine = async (data: StockInLineEntry) => {
  41. const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry>>(`${BASE_API_URL}/stockInLine/create`, {
  42. method: "POST",
  43. body: JSON.stringify(data),
  44. headers: { "Content-Type": "application/json" },
  45. });
  46. return stockInLine
  47. }
  48. export const updateStockInLine = async (data: StockInLineEntry) => {
  49. const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry>>(`${BASE_API_URL}/stockInLine/update`, {
  50. method: "POST",
  51. body: JSON.stringify(data),
  52. headers: { "Content-Type": "application/json" },
  53. });
  54. return stockInLine
  55. }