FPSMS-frontend
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

actions.ts 2.7 KiB

5 meses atrás
4 meses atrás
5 meses atrás
4 meses atrás
5 meses atrás
5 meses atrás
4 meses atrás
3 meses atrás
4 meses atrás
3 meses atrás
3 meses atrás
4 meses atrás
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 { Pageable, serverFetchJson } from "@/app/utils/fetchUtil";
  7. import { QcItemResult } from "../settings/qcItem";
  8. import { RecordsRes } from "../utils";
  9. import { convertObjToURLSearchParams } from "@/app/utils/commonUtil";
  10. import { InventoryLotLineResult, InventoryResult } from ".";
  11. // import { BASE_API_URL } from "@/config/api";
  12. export interface LotLineInfo {
  13. inventoryLotLineId: number;
  14. itemId: number;
  15. itemNo: string;
  16. itemName: string;
  17. lotNo: string;
  18. remainingQty: number;
  19. uom: string;
  20. }
  21. export interface SearchInventoryLotLine extends Pageable {
  22. itemId: number;
  23. }
  24. export interface SearchInventory extends Pageable {
  25. code: string;
  26. name: string;
  27. type: string;
  28. }
  29. export interface InventoryResultByPage {
  30. total: number;
  31. records: InventoryResult[];
  32. }
  33. export interface UpdateInventoryLotLineStatusRequest {
  34. inventoryLotLineId: number;
  35. status: string;
  36. }
  37. export interface InventoryLotLineResultByPage {
  38. total: number;
  39. records: InventoryLotLineResult[];
  40. }
  41. export interface PostInventoryLotLineResponse<T = null> {
  42. id: number | null;
  43. name: string;
  44. code: string;
  45. type?: string;
  46. message: string | null;
  47. errorPosition: string
  48. entity?: T | T[];
  49. consoCode?: string;
  50. }
  51. export const fetchLotDetail = cache(async (stockInLineId: number) => {
  52. return serverFetchJson<LotLineInfo>(
  53. `${BASE_API_URL}/inventoryLotLine/lot-detail/${stockInLineId}`,
  54. {
  55. method: "GET",
  56. next: { tags: ["inventory"] },
  57. },
  58. );
  59. });
  60. export const updateInventoryLotLineStatus = async (data: UpdateInventoryLotLineStatusRequest) => {
  61. console.log("Updating inventory lot line status:", data);
  62. const result = await serverFetchJson<PostInventoryLotLineResponse>(
  63. `${BASE_API_URL}/inventoryLotLine/updateStatus`,
  64. {
  65. method: "POST",
  66. body: JSON.stringify(data),
  67. headers: { "Content-Type": "application/json" },
  68. },
  69. );
  70. revalidateTag("inventory");
  71. return result;
  72. };
  73. export const fetchInventories = cache(async (data: SearchInventory) => {
  74. const queryStr = convertObjToURLSearchParams(data)
  75. return serverFetchJson<InventoryResultByPage>(`${BASE_API_URL}/inventory/getRecordByPage?${queryStr}`,
  76. { next: { tags: ["inventories"] } }
  77. )
  78. })
  79. export const fetchInventoryLotLines = cache(async (data: SearchInventoryLotLine) => {
  80. const queryStr = convertObjToURLSearchParams(data)
  81. return serverFetchJson<InventoryLotLineResultByPage>(`${BASE_API_URL}/inventoryLotLine/getRecordByPage?${queryStr}`, {
  82. next: { tags: ["inventoryLotLines"] },
  83. });
  84. });