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.

пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 2 недеља
пре 7 месеци
пре 2 недеља
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 7 месеци
пре 2 недеља
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. "use server";
  2. // import { serverFetchWithNoContent } from '@/app/utils/fetchUtil';
  3. // import { BASE_API_URL } from "@/config/api";
  4. import { serverFetchWithNoContent } from "../../../utils/fetchUtil";
  5. import { BASE_API_URL } from "../../../../config/api";
  6. export interface M18ImportPoForm {
  7. modifiedDateFrom: string;
  8. modifiedDateTo: string;
  9. dDateFrom: string;
  10. dDateTo: string;
  11. }
  12. export interface M18ImportDoForm {
  13. modifiedDateFrom: string;
  14. modifiedDateTo: string;
  15. dDateFrom: string;
  16. dDateTo: string;
  17. }
  18. export interface M18ImportPqForm {
  19. modifiedDateFrom: string;
  20. modifiedDateTo: string;
  21. }
  22. export interface M18ImportMasterDataForm {
  23. modifiedDateFrom: string;
  24. modifiedDateTo: string;
  25. }
  26. export interface M18ImportTestingForm {
  27. po: M18ImportPoForm;
  28. do: M18ImportDoForm;
  29. pq: M18ImportPqForm;
  30. masterData: M18ImportMasterDataForm;
  31. }
  32. export const testM18ImportPo = async (data: M18ImportPoForm) => {
  33. return serverFetchWithNoContent(`${BASE_API_URL}/m18/po`, {
  34. method: "POST",
  35. body: JSON.stringify(data),
  36. headers: { "Content-Type": "application/json" },
  37. });
  38. };
  39. export const testM18ImportDo = async (data: M18ImportDoForm) => {
  40. return serverFetchWithNoContent(`${BASE_API_URL}/m18/do`, {
  41. method: "POST",
  42. body: JSON.stringify(data),
  43. headers: { "Content-Type": "application/json" },
  44. });
  45. };
  46. export const testM18ImportPq = async (data: M18ImportPqForm) => {
  47. const token = localStorage.getItem("accessToken");
  48. return serverFetchWithNoContent(`${BASE_API_URL}/m18/pq`, {
  49. method: "POST",
  50. body: JSON.stringify(data),
  51. headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}`, },
  52. });
  53. };
  54. export const testM18ImportMasterData = async (
  55. data: M18ImportMasterDataForm,
  56. ) => {
  57. return serverFetchWithNoContent(`${BASE_API_URL}/m18/master-data`, {
  58. method: "POST",
  59. body: JSON.stringify(data),
  60. headers: { "Content-Type": "application/json" },
  61. });
  62. };
  63. export const triggerScheduler = async (type: 'po' | 'do1' | 'do2' | 'master-data' | 'refresh-cron') => {
  64. try {
  65. // IMPORTANT: 'refresh-cron' is a direct endpoint /api/scheduler/refresh-cron
  66. // Others are /api/scheduler/trigger/{type}
  67. const path = type === 'refresh-cron'
  68. ? 'refresh-cron'
  69. : `trigger/${type}`;
  70. const url = `${BASE_API_URL}/scheduler/${path}`;
  71. console.log("Fetching URL:", url);
  72. const response = await serverFetchWithNoContent(url, {
  73. method: "GET",
  74. cache: "no-store",
  75. });
  76. if (!response.ok) throw new Error(`Failed: ${response.status}`);
  77. return await response.text();
  78. } catch (error) {
  79. console.error("Scheduler Action Error:", error);
  80. return null;
  81. }
  82. };
  83. export const refreshCronSchedules = async () => {
  84. // Simply reuse the triggerScheduler logic to avoid duplication
  85. // or call serverFetch directly as shown below:
  86. try {
  87. const response = await serverFetchWithNoContent(`${BASE_API_URL}/scheduler/refresh-cron`, {
  88. method: "GET",
  89. cache: "no-store",
  90. });
  91. if (!response.ok) throw new Error(`Failed to refresh: ${response.status}`);
  92. return await response.text();
  93. } catch (error) {
  94. console.error("Refresh Cron Error:", error);
  95. return "Refresh failed. Check server logs.";
  96. }
  97. };