FPSMS-frontend
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.
 
 
 

61 line
1.3 KiB

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