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.
 
 
 

51 rivejä
1.2 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 } from ".";
  11. import { QcChecksInputs } from "../qcCheck/actions";
  12. // export type TypeInputs = {
  13. // id: number;
  14. // name: string
  15. // }
  16. // export type UomInputs = {
  17. // uom: string
  18. // }
  19. // export type WeightUnitInputs = {
  20. // weightUnit: string
  21. // conversion: number
  22. // }
  23. export type CreateItemInputs = {
  24. id?: string | number;
  25. code: string;
  26. name: string;
  27. description?: string | undefined;
  28. remarks?: string | undefined;
  29. shelfLife?: number | undefined;
  30. countryOfOrigin?: string | undefined;
  31. maxQty: number;
  32. type: string;
  33. qcChecks: QcChecksInputs[];
  34. qcChecks_active: number[];
  35. };
  36. export const saveItem = async (data: CreateItemInputs) => {
  37. const item = await serverFetchJson<CreateItemResponse<CreateItemInputs>>(
  38. `${BASE_API_URL}/items/new`,
  39. {
  40. method: "POST",
  41. body: JSON.stringify(data),
  42. headers: { "Content-Type": "application/json" },
  43. },
  44. );
  45. revalidateTag("items");
  46. return item;
  47. };