(requestBody, type)
| 33 | } |
| 34 | |
| 35 | export async function addModifyFile(requestBody, type) { |
| 36 | const endpoint = {new: ADD_FILE, edit: MODIFY_FILE}[type]; |
| 37 | if (!endpoint) { |
| 38 | throw new Error(`Invalid file mutation type: ${type}`); |
| 39 | } |
| 40 | const response = await apiRequest(endpoint, {body: requestBody}); |
| 41 | if (type === 'new') { |
| 42 | const postId = (await response.json()).PostID; |
| 43 | const postObj = { |
| 44 | Title: requestBody.content.Title, |
| 45 | PostID: postId, |
| 46 | Author: requestBody.ApplicantID, |
| 47 | type: requestBody.content.type, |
| 48 | created: Date.now(), |
| 49 | modified: Date.now() |
| 50 | }; |
| 51 | const applicant = await getApplicant(postObj.Author); |
| 52 | await setApplicant({...applicant, Posts: [...(applicant.Posts ?? []), postId]}); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | export async function removeFile(fileId, author) { |
| 57 | await apiRequest(REMOVE_FILE, {body: {PostID: fileId}}); |
no test coverage detected