Skip to content

Commit 9c5c27b

Browse files
author
dushimsam
committed
fix(MULTIPLE-API-CALLS) merge multiple upload-api calls into one
1 parent 133c1af commit 9c5c27b

File tree

3 files changed

+53
-38
lines changed

3 files changed

+53
-38
lines changed

src/api/upload.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,57 @@ export const createUploadApi = (
5555
};
5656

5757
// Create Uploads from Version Control System
58-
export const createUploadVcsApi = (header, body) => {
58+
export const createUploadVcsApi = (header, vcsData, scanData) => {
5959
const url = endpoints.upload.uploadCreate();
60+
const { bucket, copyrightEmailAuthor, ecc, keyword, mime, monk, nomos, ojo } =
61+
scanData?.analysis;
62+
const { nomosMonk, bulkReused, newScanner, ojoDecider } = scanData?.decider;
63+
const {
64+
reuseUpload,
65+
reuseGroup,
66+
reuseMain,
67+
reuseEnhanced,
68+
reuseReport,
69+
reuseCopyright,
70+
} = scanData?.reuse;
71+
6072
return sendRequest({
6173
url,
6274
method: "POST",
6375
headers: {
6476
...header,
6577
Authorization: getToken(),
6678
},
67-
body,
79+
body: {
80+
vcsData,
81+
scanOptions: {
82+
analysis: {
83+
bucket,
84+
copyright_email_author: copyrightEmailAuthor,
85+
ecc,
86+
keyword,
87+
mime,
88+
monk,
89+
nomos,
90+
ojo,
91+
package: scanData.analysis.package,
92+
},
93+
decider: {
94+
nomos_monk: nomosMonk,
95+
bulk_reused: bulkReused,
96+
new_scanner: newScanner,
97+
ojo_decider: ojoDecider,
98+
},
99+
reuse: {
100+
reuse_upload: reuseUpload,
101+
reuse_group: reuseGroup,
102+
reuse_main: reuseMain,
103+
reuse_enhanced: reuseEnhanced,
104+
reuse_report: reuseReport,
105+
reuse_copyright: reuseCopyright,
106+
},
107+
},
108+
},
68109
});
69110
};
70111

src/pages/Upload/Vcs/index.jsx

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
import React, { useState, useEffect } from "react";
20-
import messages from "constants/messages";
2120

2221
// Title
2322
import Title from "components/Title";
@@ -30,8 +29,7 @@ import CommonFields from "components/Upload/CommonFields";
3029

3130
// Required functions for calling APIs
3231
import { getAllFolders } from "services/folders";
33-
import { createUploadVcs, getUploadById } from "services/upload";
34-
import { scheduleAnalysis } from "services/jobs";
32+
import { createUploadVcs } from "services/upload";
3533

3634
// Default Agents list
3735
import {
@@ -44,11 +42,9 @@ import {
4442

4543
// Helper function for error handling
4644
import { handleError } from "shared/helper";
45+
import messages from "../../../constants/messages";
4746

4847
const UploadFromVcs = () => {
49-
// Upload Id required for scheduling Analysis
50-
let uploadId;
51-
5248
// Data required for creating the upload
5349
const [uploadVcsData, setUploadVcsData] = useState(initialStateVcs);
5450

@@ -69,36 +65,14 @@ const UploadFromVcs = () => {
6965
const handleSubmit = (e) => {
7066
e.preventDefault();
7167
setLoading(true);
72-
createUploadVcs(uploadVcsData, vcsData)
73-
.then((res) => {
68+
createUploadVcs(uploadVcsData, vcsData, scanFileData)
69+
.then(() => {
7470
window.scrollTo({ top: 0 });
7571
setMessage({
7672
type: "success",
77-
text: `${messages.queuedUpload} #${res.message}`,
73+
text: `${messages.uploadSuccess}`,
7874
});
79-
uploadId = res.message;
8075
})
81-
// Calling the api for maximum 10 times to check whether the upload is unpacked by the agent
82-
.then(() => getUploadById(uploadId, 10))
83-
.then(() =>
84-
setTimeout(
85-
() =>
86-
scheduleAnalysis(uploadVcsData.folderId, uploadId, scanFileData)
87-
.then(() => {
88-
window.scrollTo({ top: 0 });
89-
setMessage({
90-
type: "success",
91-
text: messages.scheduledAnalysis,
92-
});
93-
setUploadVcsData(initialStateVcs);
94-
setScanFileData(initialScanFileData);
95-
})
96-
.catch((error) => {
97-
handleError(error, setMessage);
98-
}),
99-
200000
100-
)
101-
)
10276
.catch((error) => {
10377
handleError(error, setMessage);
10478
})

src/services/upload.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export const createUploadFile = ({
4242
};
4343

4444
// Create Uploads from Version Control System
45-
export const createUploadVcs = (header, body) => {
46-
return createUploadVcsApi(header, body).then((res) => {
45+
export const createUploadVcs = (header, vcsData, scanData) => {
46+
return createUploadVcsApi(header, vcsData, scanData).then((res) => {
4747
return res;
4848
});
4949
};
@@ -55,21 +55,21 @@ export const createUploadUrl = (header, body) => {
5555
});
5656
};
5757

58-
// Getting a Upload by id
58+
// Getting an Upload by id
5959
export const getUploadById = (uploadId, retries) => {
6060
return getUploadByIdApi(uploadId, retries).then((res) => {
6161
return res;
6262
});
6363
};
6464

65-
// Getting a Upload Summary
65+
// Getting an Upload Summary
6666
export const getUploadSummary = (uploadId) => {
6767
return getUploadSummaryApi(uploadId).then((res) => {
6868
return res;
6969
});
7070
};
7171

72-
// Getting a Upload License
72+
// Getting an Upload License
7373
export const getUploadLicense = (uploadId, agent) => {
7474
return getUploadLicenseApi(uploadId, agent).then((res) => {
7575
return res;

0 commit comments

Comments
 (0)