system-praktyk-front/src/api/upload.ts
2020-11-06 20:03:14 +01:00

26 lines
810 B
TypeScript

import { axios } from "@/api/index";
import { InternshipDocument } from "@/api/dto/internship-registration";
import { prepare } from "@/routing";
export enum UploadType {
Ipp = "IppScan",
DeanConsent = "DeanConsent",
Insurance = "NnwInsurance",
}
const CREATE_DOCUMENT_ENDPOINT = '/document';
const DOCUMENT_UPLOAD_ENDPOINT = '/document/:id/scan';
export async function create(type: UploadType) {
const response = await axios.post<InternshipDocument>(CREATE_DOCUMENT_ENDPOINT, { type });
return response.data;
}
export async function upload(document: InternshipDocument, file: File) {
const data = new FormData();
data.append('documentScan', file)
const response = await axios.put(prepare(DOCUMENT_UPLOAD_ENDPOINT, { id: document.id as string }), data);
return true;
}