您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

48 行
1.1 KiB

  1. "use server"
  2. import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  3. import { BASE_API_URL } from "@/config/api";
  4. import { cache } from "react";
  5. export interface comboProp {
  6. id: any;
  7. label: string;
  8. }
  9. export interface combo {
  10. records: comboProp[];
  11. }
  12. export interface CreateDepartmentInputs {
  13. id: number;
  14. code: string;
  15. name: string;
  16. description: string;
  17. }
  18. export const saveDepartment = async (data: CreateDepartmentInputs) => {
  19. return serverFetchJson(`${BASE_API_URL}/departments/new`, {
  20. method: "POST",
  21. body: JSON.stringify(data),
  22. headers: { "Content-Type": "application/json" },
  23. });
  24. };
  25. export const deleteDepartment = async (id: number) => {
  26. const department = await serverFetchWithNoContent(
  27. `${BASE_API_URL}/departments/${id}`,
  28. {
  29. method: "DELETE",
  30. headers: { "Content-Type": "application/json" },
  31. },
  32. );
  33. return department
  34. };
  35. export const fetchDepartmentCombo = cache(async () => {
  36. return serverFetchJson<combo>(`${BASE_API_URL}/departments/combo`, {
  37. next: { tags: ["department"] },
  38. });
  39. });