|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- "use server";
- import {
- ServerFetchError,
- serverFetchJson,
- serverFetchWithNoContent,
- } from "@/app/utils/fetchUtil";
- import { revalidateTag, revalidatePath } from "next/cache";
- import { BASE_API_URL } from "@/config/api";
- import { CreateItemResponse, RecordsRes } from "../../utils";
- import { ItemQc, ItemsResult } from ".";
- import { QcChecksInputs } from "../qcCheck/actions";
- import { cache } from "react";
-
-
- // export type TypeInputs = {
- // id: number;
- // name: string
- // }
- // export type UomInputs = {
- // uom: string
- // }
- // export type WeightUnitInputs = {
- // weightUnit: string
- // conversion: number
- // }
-
- export type CreateItemInputs = {
- id?: string | number;
- code: string;
- name: string;
- description?: string | undefined;
- remarks?: string | undefined;
- shelfLife?: number | undefined;
- countryOfOrigin?: string | undefined;
- maxQty: number;
- type: string;
- qcChecks: QcChecksInputs[];
- qcChecks_active: number[];
- qcCategoryId: number | undefined;
- store_id?: string | undefined;
- warehouse?: string | undefined;
- area?: string | undefined;
- slot?: string | undefined;
- LocationCode?: string | undefined;
- isEgg?: boolean | undefined;
- isFee?: boolean | undefined;
- isBag?: boolean | undefined;
- qcType?: string | undefined;
- };
-
- export const saveItem = async (data: CreateItemInputs) => {
- const item = await serverFetchJson<CreateItemResponse<CreateItemInputs>>(
- `${BASE_API_URL}/items/new`,
- {
- method: "POST",
- body: JSON.stringify(data),
- headers: { "Content-Type": "application/json" },
- },
- );
- revalidateTag("items");
- return item;
- };
-
- export const deleteItem = async (id: number) => {
- const response = await serverFetchJson<ItemsResult>(
- `${BASE_API_URL}/items/${id}`,
- {
- method: "DELETE",
- headers: { "Content-Type": "application/json" },
- },
- );
-
- revalidateTag("items");
- revalidatePath("/(main)/settings/items");
-
- return response;
- };
-
- export interface ItemCombo {
- id: number,
- label: string,
- uomId: number,
- uom: string,
- uomDesc: string,
- group?: string,
- currentStockBalance?: number,
- }
- export interface ItemWithDetails {
- id: number;
- code: string;
- name: string;
- description?: string;
- uomId: number;
- uom: string;
- uomDesc: string;
- currentStockBalance: number;
- }
- export const fetchItemsWithDetails = cache(async (searchParams?: Record<string, any>) => {
- if (searchParams) {
- const queryString = new URLSearchParams(searchParams).toString();
- return serverFetchJson<RecordsRes<ItemWithDetails>>(
- `${BASE_API_URL}/items/itemsWithDetails?${queryString}`,
- {
- next: { tags: ["items"] },
- }
- );
- } else {
- return serverFetchJson<RecordsRes<ItemWithDetails>>(
- `${BASE_API_URL}/items/itemsWithDetails`,
- {
- next: { tags: ["items"] },
- }
- );
- }
- });
-
- export const fetchAllItemsInClient = cache(async () => {
- return serverFetchJson<ItemCombo[]>(`${BASE_API_URL}/items/consumables`, {
- next: { tags: ["items"] },
- });
- });
- export const fetchPickOrderItemsByPageClient = cache(
- async (queryParams?: Record<string, any>) => {
- if (queryParams) {
- const queryString = new URLSearchParams(queryParams).toString();
- return serverFetchJson<RecordsRes<any>>(
- `${BASE_API_URL}/items/pickOrderItems?${queryString}`,
- {
- method: "GET",
- next: { tags: ["pickorder"] },
- },
- );
- } else {
- return serverFetchJson<RecordsRes<any>>(
- `${BASE_API_URL}/items/pickOrderItems`,
- {
- method: "GET",
- next: { tags: ["pickorder"] },
- },
- );
- }
- },
- );
|