MCPcopy Create free account
hub / github.com/OpenSIST/OpenSIST.github.io / addModifyFile

Function addModifyFile

src/Data/FileData.js:35–54  ·  view source on GitHub ↗
(requestBody, type)

Source from the content-addressed store, hash-verified

33}
34
35export 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
56export async function removeFile(fileId, author) {
57 await apiRequest(REMOVE_FILE, {body: {PostID: fileId}});

Callers 1

syncApplicantFileFunction · 0.90

Calls 3

apiRequestFunction · 0.90
getApplicantFunction · 0.90
setApplicantFunction · 0.90

Tested by

no test coverage detected