Skip to content

Commit

Permalink
fix(MULTIPLE-API-CALLS) merge multiple upload-api calls into one
Browse files Browse the repository at this point in the history
  • Loading branch information
dushimsam committed Aug 10, 2022
1 parent 133c1af commit 9c5c27b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 38 deletions.
45 changes: 43 additions & 2 deletions src/api/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,57 @@ export const createUploadApi = (
};

// Create Uploads from Version Control System
export const createUploadVcsApi = (header, body) => {
export const createUploadVcsApi = (header, vcsData, scanData) => {
const url = endpoints.upload.uploadCreate();
const { bucket, copyrightEmailAuthor, ecc, keyword, mime, monk, nomos, ojo } =
scanData?.analysis;
const { nomosMonk, bulkReused, newScanner, ojoDecider } = scanData?.decider;
const {
reuseUpload,
reuseGroup,
reuseMain,
reuseEnhanced,
reuseReport,
reuseCopyright,
} = scanData?.reuse;

return sendRequest({
url,
method: "POST",
headers: {
...header,
Authorization: getToken(),
},
body,
body: {
vcsData,
scanOptions: {
analysis: {
bucket,
copyright_email_author: copyrightEmailAuthor,
ecc,
keyword,
mime,
monk,
nomos,
ojo,
package: scanData.analysis.package,
},
decider: {
nomos_monk: nomosMonk,
bulk_reused: bulkReused,
new_scanner: newScanner,
ojo_decider: ojoDecider,
},
reuse: {
reuse_upload: reuseUpload,
reuse_group: reuseGroup,
reuse_main: reuseMain,
reuse_enhanced: reuseEnhanced,
reuse_report: reuseReport,
reuse_copyright: reuseCopyright,
},
},
},
});
};

Expand Down
36 changes: 5 additions & 31 deletions src/pages/Upload/Vcs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

import React, { useState, useEffect } from "react";
import messages from "constants/messages";

// Title
import Title from "components/Title";
Expand All @@ -30,8 +29,7 @@ import CommonFields from "components/Upload/CommonFields";

// Required functions for calling APIs
import { getAllFolders } from "services/folders";
import { createUploadVcs, getUploadById } from "services/upload";
import { scheduleAnalysis } from "services/jobs";
import { createUploadVcs } from "services/upload";

// Default Agents list
import {
Expand All @@ -44,11 +42,9 @@ import {

// Helper function for error handling
import { handleError } from "shared/helper";
import messages from "../../../constants/messages";

const UploadFromVcs = () => {
// Upload Id required for scheduling Analysis
let uploadId;

// Data required for creating the upload
const [uploadVcsData, setUploadVcsData] = useState(initialStateVcs);

Expand All @@ -69,36 +65,14 @@ const UploadFromVcs = () => {
const handleSubmit = (e) => {
e.preventDefault();
setLoading(true);
createUploadVcs(uploadVcsData, vcsData)
.then((res) => {
createUploadVcs(uploadVcsData, vcsData, scanFileData)
.then(() => {
window.scrollTo({ top: 0 });
setMessage({
type: "success",
text: `${messages.queuedUpload} #${res.message}`,
text: `${messages.uploadSuccess}`,
});
uploadId = res.message;
})
// Calling the api for maximum 10 times to check whether the upload is unpacked by the agent
.then(() => getUploadById(uploadId, 10))
.then(() =>
setTimeout(
() =>
scheduleAnalysis(uploadVcsData.folderId, uploadId, scanFileData)
.then(() => {
window.scrollTo({ top: 0 });
setMessage({
type: "success",
text: messages.scheduledAnalysis,
});
setUploadVcsData(initialStateVcs);
setScanFileData(initialScanFileData);
})
.catch((error) => {
handleError(error, setMessage);
}),
200000
)
)
.catch((error) => {
handleError(error, setMessage);
})
Expand Down
10 changes: 5 additions & 5 deletions src/services/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const createUploadFile = ({
};

// Create Uploads from Version Control System
export const createUploadVcs = (header, body) => {
return createUploadVcsApi(header, body).then((res) => {
export const createUploadVcs = (header, vcsData, scanData) => {
return createUploadVcsApi(header, vcsData, scanData).then((res) => {
return res;
});
};
Expand All @@ -55,21 +55,21 @@ export const createUploadUrl = (header, body) => {
});
};

// Getting a Upload by id
// Getting an Upload by id
export const getUploadById = (uploadId, retries) => {
return getUploadByIdApi(uploadId, retries).then((res) => {
return res;
});
};

// Getting a Upload Summary
// Getting an Upload Summary
export const getUploadSummary = (uploadId) => {
return getUploadSummaryApi(uploadId).then((res) => {
return res;
});
};

// Getting a Upload License
// Getting an Upload License
export const getUploadLicense = (uploadId, agent) => {
return getUploadLicenseApi(uploadId, agent).then((res) => {
return res;
Expand Down

0 comments on commit 9c5c27b

Please sign in to comment.