FPSMS-frontend
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

62 rindas
1.6 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. brand?: string;
  14. description?: string;
  15. ip?: string;
  16. port?: number;
  17. dpi?: number;
  18. }
  19. export const fetchPrinterDetails = async (id: number) => {
  20. return serverFetchJson<PrinterResult>(`${BASE_API_URL}/printers/${id}`, {
  21. next: { tags: ["printers"] },
  22. });
  23. };
  24. export const editPrinter = async (id: number, data: PrinterInputs) => {
  25. const result = await serverFetchWithNoContent(`${BASE_API_URL}/printers/${id}`, {
  26. method: "PUT",
  27. body: JSON.stringify(data),
  28. headers: { "Content-Type": "application/json" },
  29. });
  30. revalidateTag("printers");
  31. return result;
  32. };
  33. export const createPrinter = async (data: PrinterInputs) => {
  34. const result = await serverFetchWithNoContent(`${BASE_API_URL}/printers`, {
  35. method: "POST",
  36. body: JSON.stringify(data),
  37. headers: { "Content-Type": "application/json" },
  38. });
  39. revalidateTag("printers");
  40. return result;
  41. };
  42. export const deletePrinter = async (id: number) => {
  43. const result = await serverFetchWithNoContent(`${BASE_API_URL}/printers/${id}`, {
  44. method: "DELETE",
  45. headers: { "Content-Type": "application/json" },
  46. });
  47. revalidateTag("printers");
  48. return result;
  49. };
  50. export const fetchPrinterDescriptions = async () => {
  51. return serverFetchJson<string[]>(`${BASE_API_URL}/printers/descriptions`, {
  52. next: { tags: ["printers"] },
  53. });
  54. };