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.
 
 

106 lines
3.1 KiB

  1. "use client";
  2. import axiosInstance from "@/app/(main)/axios/axiosInstance";
  3. import { NEXT_PUBLIC_API_URL } from "@/config/api";
  4. import type {
  5. BomFormatCheckResponse,
  6. BomUploadResponse,
  7. ImportBomItemPayload,
  8. BomCombo,
  9. BomDetailResponse,
  10. } from "./index";
  11. export async function uploadBomFiles(
  12. files: File[]
  13. ): Promise<BomUploadResponse> {
  14. const formData = new FormData();
  15. files.forEach((f) => formData.append("files", f, f.name));
  16. const response = await axiosInstance.post<BomUploadResponse>(
  17. `${NEXT_PUBLIC_API_URL}/bom/import-bom/upload`,
  18. formData,
  19. {
  20. transformRequest: [
  21. (data: unknown, headers?: Record<string, unknown>) => {
  22. if (data instanceof FormData && headers && "Content-Type" in headers) {
  23. delete headers["Content-Type"];
  24. }
  25. return data;
  26. },
  27. ],
  28. }
  29. );
  30. return response.data;
  31. }
  32. export async function checkBomFormat(
  33. batchId: string
  34. ): Promise<BomFormatCheckResponse> {
  35. const response = await axiosInstance.post<BomFormatCheckResponse>(
  36. `${NEXT_PUBLIC_API_URL}/bom/import-bom/format-check`,
  37. { batchId }
  38. );
  39. return response.data;
  40. }
  41. export async function downloadBomFormatIssueLog(
  42. batchId: string,
  43. issueLogFileId: string
  44. ): Promise<Blob> {
  45. const response = await axiosInstance.get(
  46. `${NEXT_PUBLIC_API_URL}/bom/import-bom/format-issue-log`,
  47. {
  48. params: { batchId, issueLogFileId },
  49. responseType: "blob",
  50. }
  51. );
  52. return response.data as Blob;
  53. }
  54. export async function importBom(
  55. batchId: string,
  56. items: ImportBomItemPayload[]
  57. ): Promise<Blob> {
  58. const response = await axiosInstance.post(
  59. `${NEXT_PUBLIC_API_URL}/bom/import-bom`,
  60. { batchId, items },
  61. { responseType: "blob" }
  62. );
  63. return response.data as Blob;
  64. }
  65. import type { BomScoreResult } from "./index";
  66. export const fetchBomScoresClient = async (): Promise<BomScoreResult[]> => {
  67. const response = await axiosInstance.get<BomScoreResult[]>(
  68. `${NEXT_PUBLIC_API_URL}/bom/scores`,
  69. );
  70. return response.data;
  71. };
  72. export async function fetchBomComboClient(): Promise<BomCombo[]> {
  73. const response = await axiosInstance.get<BomCombo[]>(
  74. `${NEXT_PUBLIC_API_URL}/bom/combo`
  75. );
  76. return response.data;
  77. }
  78. export async function fetchBomDetailClient(id: number): Promise<BomDetailResponse> {
  79. const response = await axiosInstance.get<BomDetailResponse>(
  80. `${NEXT_PUBLIC_API_URL}/bom/${id}/detail`
  81. );
  82. return response.data;
  83. }
  84. export type BomExcelCheckProgress = {
  85. batchId: string;
  86. totalFiles: number;
  87. processedFiles: number;
  88. currentFileName: string | null;
  89. lastUpdateTime: number;
  90. };
  91. export async function getBomFormatProgress(
  92. batchId: string
  93. ): Promise<BomExcelCheckProgress> {
  94. const response = await axiosInstance.get<BomExcelCheckProgress>(
  95. `${NEXT_PUBLIC_API_URL}/bom/import-bom/format-check/progress`,
  96. { params: { batchId } }
  97. );
  98. return response.data;
  99. }