FPSMS-frontend
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

65 行
1.5 KiB

  1. "use server";
  2. import {
  3. ServerFetchError,
  4. serverFetchJson,
  5. serverFetchWithNoContent,
  6. } from "@/app/utils/fetchUtil";
  7. import { revalidateTag } from "next/cache";
  8. import { BASE_API_URL } from "@/config/api";
  9. import { CreateItemResponse } from "../../utils";
  10. import { ItemQc, ItemsResult } from ".";
  11. import { QcChecksInputs } from "../qcCheck/actions";
  12. import { cache } from "react";
  13. // export type TypeInputs = {
  14. // id: number;
  15. // name: string
  16. // }
  17. // export type UomInputs = {
  18. // uom: string
  19. // }
  20. // export type WeightUnitInputs = {
  21. // weightUnit: string
  22. // conversion: number
  23. // }
  24. export type CreateItemInputs = {
  25. id?: string | number;
  26. code: string;
  27. name: string;
  28. description?: string | undefined;
  29. remarks?: string | undefined;
  30. shelfLife?: number | undefined;
  31. countryOfOrigin?: string | undefined;
  32. maxQty: number;
  33. type: string;
  34. qcChecks: QcChecksInputs[];
  35. qcChecks_active: number[];
  36. };
  37. export const saveItem = async (data: CreateItemInputs) => {
  38. const item = await serverFetchJson<CreateItemResponse<CreateItemInputs>>(
  39. `${BASE_API_URL}/items/new`,
  40. {
  41. method: "POST",
  42. body: JSON.stringify(data),
  43. headers: { "Content-Type": "application/json" },
  44. },
  45. );
  46. revalidateTag("items");
  47. return item;
  48. };
  49. export interface ItemCombo {
  50. id: number,
  51. label: string,
  52. uomId: number,
  53. uom: string,
  54. }
  55. export const fetchAllItemsInClient = cache(async () => {
  56. return serverFetchJson<ItemCombo[]>(`${BASE_API_URL}/items/consumables`, {
  57. next: { tags: ["items"] },
  58. });
  59. });