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

74 行
2.2 KiB

  1. "use server";
  2. // import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  3. // import { BASE_API_URL } from "@/config/api";
  4. import { serverFetchJson, serverFetchWithNoContent } from "../../utils/fetchUtil";
  5. import { BASE_API_URL } from "../../../config/api";
  6. import { revalidateTag } from "next/cache";
  7. import { UserDetail, UserResult } from ".";
  8. import { cache } from "react";
  9. export interface UserInputs {
  10. username: string;
  11. // name: string;
  12. addAuthIds?: number[];
  13. removeAuthIds?: number[];
  14. password?: string;
  15. }
  16. export interface PasswordInputs {
  17. password: string;
  18. newPassword: string;
  19. newPasswordCheck: string;
  20. }
  21. export const fetchUserDetails = cache(async (id: number) => {
  22. return serverFetchJson<UserDetail>(`${BASE_API_URL}/user/${id}`, {
  23. next: { tags: ["user"] },
  24. });
  25. });
  26. export const editUser = async (id: number, data: UserInputs) => {
  27. const newUser = serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, {
  28. method: "PUT",
  29. body: JSON.stringify(data),
  30. headers: { "Content-Type": "application/json" },
  31. });
  32. revalidateTag("user")
  33. return newUser
  34. };
  35. export const createUser = async (data: UserInputs) => {
  36. const newUser = serverFetchWithNoContent(`${BASE_API_URL}/user/save`, {
  37. method: "POST",
  38. body: JSON.stringify(data),
  39. headers: { "Content-Type": "application/json" },
  40. });
  41. revalidateTag("user")
  42. return newUser
  43. };
  44. export const deleteUser = async (id: number) => {
  45. const newUser = serverFetchWithNoContent(`${BASE_API_URL}/user/${id}`, {
  46. method: "DELETE",
  47. headers: { "Content-Type": "application/json" },
  48. });
  49. revalidateTag("user")
  50. return newUser
  51. };
  52. export const changePassword = async (data: any) => {
  53. return serverFetchWithNoContent(`${BASE_API_URL}/user/change-password`, {
  54. method: "PATCH",
  55. body: JSON.stringify(data),
  56. headers: { "Content-Type": "application/json" },
  57. });
  58. };
  59. export const adminChangePassword = async (data: any) => {
  60. return serverFetchWithNoContent(`${BASE_API_URL}/user/admin-change-password`, {
  61. method: "PATCH",
  62. body: JSON.stringify(data),
  63. headers: { "Content-Type": "application/json" },
  64. });
  65. };