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.
 
 

73 line
1.7 KiB

  1. import { cache } from "react";
  2. import "server-only";
  3. // import { serverFetchJson } from "@/app/utils/fetchUtil";
  4. // import { BASE_API_URL } from "@/config/api";
  5. import { serverFetchJson } from "../../../utils/fetchUtil";
  6. import { BASE_API_URL } from "../../../../config/api";
  7. import { QcCategoryResult } from "../qcCategory";
  8. import { Uom } from "../uom";
  9. // import { TypeInputs, UomInputs, WeightUnitInputs } from "./actions";
  10. export type ItemQc = {
  11. id: number; // id = qc_check #
  12. name: string;
  13. code: string;
  14. description: string | undefined;
  15. instruction: string | undefined;
  16. lowerLimit: number | undefined;
  17. upperLimit: number | undefined;
  18. isActive: boolean | undefined;
  19. };
  20. export type ItemsResultResponse = {
  21. records: ItemsResult[];
  22. total: number;
  23. };
  24. export type Item = {
  25. id: number;
  26. code: string;
  27. name: string;
  28. description?: string;
  29. remarks?: string;
  30. type?: string;
  31. shelfLife?: number;
  32. countryOfOrigin?: string;
  33. qcCategory?: QcCategoryResult;
  34. uom: Uom;
  35. }
  36. export type ItemsResult = {
  37. id: string | number;
  38. code: string;
  39. name: string;
  40. description: string | undefined;
  41. remarks: string | undefined;
  42. shelfLife: number | undefined;
  43. countryOfOrigin: string | undefined;
  44. maxQty: number | undefined;
  45. type: string;
  46. qcChecks: ItemQc[];
  47. action?: any;
  48. fgName?: string;
  49. excludeDate?: string;
  50. qcCategory?: QcCategoryResult;
  51. };
  52. export type Result = {
  53. item: ItemsResult;
  54. qcChecks: ItemQc[];
  55. };
  56. export const fetchAllItems = cache(async () => {
  57. return serverFetchJson<ItemsResult[]>(`${BASE_API_URL}/items`, {
  58. next: { tags: ["items"] },
  59. });
  60. });
  61. export const fetchItem = cache(async (id: number) => {
  62. return serverFetchJson<Result>(`${BASE_API_URL}/items/details/${id}`, {
  63. next: { tags: ["items"] },
  64. });
  65. });