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.

55 lines
1.4 KiB

  1. "use server";
  2. import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  3. import { BASE_API_URL } from "@/config/api";
  4. import { revalidateTag } from "next/cache";
  5. import { cache } from "react";
  6. export interface CreateGroupInputs {
  7. id?: number;
  8. name: string;
  9. description: string;
  10. addUserIds?: number[];
  11. removeUserIds?: number[];
  12. addAuthIds?: number[];
  13. removeAuthIds?: number[];
  14. }
  15. export interface auth {
  16. id: number;
  17. module?: any | null;
  18. authority: string;
  19. name: string;
  20. description: string | null;
  21. v: number;
  22. }
  23. export interface record {
  24. records: auth[];
  25. }
  26. export const fetchAuth = cache(async (target: string, id?: number ) => {
  27. return serverFetchJson<record>(`${BASE_API_URL}/group/auth/${target}/${id ?? 0}`, {
  28. next: { tags: ["auth"] },
  29. });
  30. });
  31. export const saveGroup = async (data: CreateGroupInputs) => {
  32. const newGroup = serverFetchJson(`${BASE_API_URL}/group/save`, {
  33. method: "POST",
  34. body: JSON.stringify(data),
  35. headers: { "Content-Type": "application/json" },
  36. });
  37. revalidateTag("group")
  38. return newGroup
  39. };
  40. export const deleteGroup = async (id: number) => {
  41. const newGroup = serverFetchWithNoContent(`${BASE_API_URL}/group/${id}`, {
  42. method: "DELETE",
  43. headers: { "Content-Type": "application/json" },
  44. });
  45. revalidateTag("group")
  46. return newGroup
  47. };