system-praktyk-front/src/api/upload.ts
2020-11-07 15:47:07 +01:00

38 lines
1.2 KiB
TypeScript

import { axios } from "@/api/index";
import { InternshipDocument } from "@/api/dto/internship-registration";
import { prepare } from "@/routing";
import { Identifiable } from "@/data";
export enum UploadType {
Ipp = "IppScan",
DeanConsent = "DeanConsent",
Insurance = "NnwInsurance",
}
export interface DocumentFileInfo extends Identifiable {
filename: string;
size: number;
mime: string;
}
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;
}
export async function fileinfo(document: InternshipDocument): Promise<DocumentFileInfo> {
const response = await axios.get<DocumentFileInfo>(prepare(DOCUMENT_UPLOAD_ENDPOINT, { id: document.id as string }));
return response.data;
}