FPSMS-frontend
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

actions.ts 2.2 KiB

9 miesięcy temu
9 miesięcy temu
3 miesięcy temu
5 miesięcy temu
5 miesięcy temu
3 miesięcy temu
9 miesięcy temu
9 miesięcy temu
4 miesięcy temu
9 miesięcy temu
9 miesięcy temu
5 miesięcy temu
3 miesięcy temu
3 miesięcy temu
5 miesięcy temu
3 miesięcy temu
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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, RecordsRes } 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. qcCategoryId: number | undefined;
  37. };
  38. export const saveItem = async (data: CreateItemInputs) => {
  39. const item = await serverFetchJson<CreateItemResponse<CreateItemInputs>>(
  40. `${BASE_API_URL}/items/new`,
  41. {
  42. method: "POST",
  43. body: JSON.stringify(data),
  44. headers: { "Content-Type": "application/json" },
  45. },
  46. );
  47. revalidateTag("items");
  48. return item;
  49. };
  50. export interface ItemCombo {
  51. id: number,
  52. label: string,
  53. uomId: number,
  54. uom: string,
  55. uomDesc: string,
  56. group?: string,
  57. currentStockBalance?: number,
  58. }
  59. export const fetchAllItemsInClient = cache(async () => {
  60. return serverFetchJson<ItemCombo[]>(`${BASE_API_URL}/items/consumables`, {
  61. next: { tags: ["items"] },
  62. });
  63. });
  64. export const fetchPickOrderItemsByPageClient = cache(
  65. async (queryParams?: Record<string, any>) => {
  66. if (queryParams) {
  67. const queryString = new URLSearchParams(queryParams).toString();
  68. return serverFetchJson<RecordsRes<any>>(
  69. `${BASE_API_URL}/items/pickOrderItems?${queryString}`,
  70. {
  71. method: "GET",
  72. next: { tags: ["pickorder"] },
  73. },
  74. );
  75. } else {
  76. return serverFetchJson<RecordsRes<any>>(
  77. `${BASE_API_URL}/items/pickOrderItems`,
  78. {
  79. method: "GET",
  80. next: { tags: ["pickorder"] },
  81. },
  82. );
  83. }
  84. },
  85. );