FPSMS-frontend
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

54 řádky
1.4 KiB

  1. "use server";
  2. import {
  3. serverFetchJson,
  4. serverFetchWithNoContent,
  5. } from "../../../utils/fetchUtil";
  6. import { BASE_API_URL } from "../../../../config/api";
  7. import { revalidateTag } from "next/cache";
  8. import { PrinterResult } from ".";
  9. export interface PrinterInputs {
  10. name?: string;
  11. code?: string;
  12. type?: string;
  13. description?: string;
  14. ip?: string;
  15. port?: number;
  16. }
  17. export const fetchPrinterDetails = async (id: number) => {
  18. return serverFetchJson<PrinterResult>(`${BASE_API_URL}/printers/${id}`, {
  19. next: { tags: ["printers"] },
  20. });
  21. };
  22. export const editPrinter = async (id: number, data: PrinterInputs) => {
  23. const result = await serverFetchWithNoContent(`${BASE_API_URL}/printers/${id}`, {
  24. method: "PUT",
  25. body: JSON.stringify(data),
  26. headers: { "Content-Type": "application/json" },
  27. });
  28. revalidateTag("printers");
  29. return result;
  30. };
  31. export const createPrinter = async (data: PrinterInputs) => {
  32. const result = await serverFetchWithNoContent(`${BASE_API_URL}/printers`, {
  33. method: "POST",
  34. body: JSON.stringify(data),
  35. headers: { "Content-Type": "application/json" },
  36. });
  37. revalidateTag("printers");
  38. return result;
  39. };
  40. export const deletePrinter = async (id: number) => {
  41. const result = await serverFetchWithNoContent(`${BASE_API_URL}/printers/${id}`, {
  42. method: "DELETE",
  43. headers: { "Content-Type": "application/json" },
  44. });
  45. revalidateTag("printers");
  46. return result;
  47. };