61 lines
1.8 KiB
TypeScript
Executable File
61 lines
1.8 KiB
TypeScript
Executable File
import API from './axiosConfig';
|
|
import { DesignStageResponse, DesignStageFileRequest, DesignStageFileResponse } from 'interfaces/API/draft';
|
|
import objectToFormDataConverter from 'helpers/objectToFormDataConverter';
|
|
import { AxiosResponse } from 'axios';
|
|
|
|
const getPrintingFileById = async (printingFileId: number): Promise<DesignStageResponse | null> => {
|
|
try {
|
|
const response = await API.get<DesignStageResponse>(`/pfs/${printingFileId}/`);
|
|
return response.data;
|
|
} catch (err) {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
const addPrintingFilesFile = async (
|
|
printingFileId: number,
|
|
data: DesignStageFileRequest
|
|
): Promise<DesignStageFileResponse | null> => {
|
|
try {
|
|
const formData = objectToFormDataConverter(data);
|
|
const response = await API.post<DesignStageFileResponse>(`/pfs/${printingFileId}/files/`, formData);
|
|
return response.data;
|
|
} catch (err) {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
const acceptPrintingFilesFile = async (printingFileId: number): Promise<DesignStageResponse | null> => {
|
|
try {
|
|
const response = await API.patch<DesignStageResponse>(`/pfs/${printingFileId}/`, { accept: true });
|
|
return response.data;
|
|
} catch (err) {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
const openPrintingFile = async (pringintFileId: number) => {
|
|
try {
|
|
const response = await API.get<AxiosResponse>(`/printing-files-files/${pringintFileId}/open-file/`);
|
|
return response.data;
|
|
} catch (err) {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
export default {
|
|
openPrintingFile,
|
|
getPrintingFileById,
|
|
addPrintingFilesFile,
|
|
acceptPrintingFilesFile,
|
|
};
|
|
// export const fetchDrafts = async (productId: number): Promise<DraftResponse[] | []> => {
|
|
// try {
|
|
// const response = await API.get<DraftResponse[]>('');
|
|
// return response.data;
|
|
// } catch (err) {
|
|
// console.error(err);
|
|
// return [];
|
|
// }
|
|
// };
|