Skip to content

Commit 76b66e3

Browse files
Merge pull request #124 from sumitdaga/issue-ca-3575
update DELETE submission api to V5 :
2 parents f1c2380 + e7ef509 commit 76b66e3

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

config/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
API: {
33
V2: 'https://api.topcoder-dev.com/v2',
44
V3: 'https://api.topcoder-dev.com/v3',
5+
V5: 'https://api.topcoder-dev.com/v5',
56
},
67
dummyConfigKey: 'Dummy config value',
78
SECRET: {

src/actions/smp.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import _ from 'lodash';
77
import { createActions } from 'redux-actions';
88
import { getApi } from '../services/api';
9+
import { getService as getSubmissionService } from '../services/submissions';
910

1011
/**
1112
* @static
@@ -17,13 +18,25 @@ function deleteSubmissionInit() {}
1718
/**
1819
* @static
1920
* @desc Creates an action that deletes user's submission to a challenge.
20-
* @param {String} tokenV3 Topcoder v3 auth token.
21+
* @param {String} tokenV5 Topcoder v5 auth token.
2122
* @param {Number|String} submissionId Submission ID.
2223
* @return {Action}
2324
*/
24-
function deleteSubmissionDone(tokenV3, submissionId) {
25-
return getApi('V3', tokenV3).delete(`/submissions/${submissionId}`)
26-
.then(() => submissionId);
25+
function deleteSubmissionDone(tokenV5, submissionId) {
26+
const submissionsService = getSubmissionService(tokenV5);
27+
const filters = { legacySubmissionId: submissionId };
28+
29+
// from the legacy submissionId first get the GUID of the submission
30+
// and pass that id to the V5 api
31+
return submissionsService.getSubmissions(filters, {})
32+
.then((submissions) => {
33+
if (submissions.length === 0) {
34+
throw new Error(`Submission ${submissionId} does not exist.`);
35+
}
36+
return getApi('V5', tokenV5).delete(`/submissions/${submissions[0].id}`)
37+
.then(res => (res.ok ? submissionId : new Error(res.statusText)))
38+
.then(res => res);
39+
});
2740
}
2841

2942
/**

0 commit comments

Comments
 (0)