Skip to content

update DELETE submission api to V5 #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
API: {
V2: 'https://api.topcoder-dev.com/v2',
V3: 'https://api.topcoder-dev.com/v3',
V5: 'https://api.topcoder-dev.com/v5',
},
dummyConfigKey: 'Dummy config value',
SECRET: {
Expand Down
21 changes: 17 additions & 4 deletions src/actions/smp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import _ from 'lodash';
import { createActions } from 'redux-actions';
import { getApi } from '../services/api';
import { getService as getSubmissionService } from '../services/submissions';

/**
* @static
Expand All @@ -17,13 +18,25 @@ function deleteSubmissionInit() {}
/**
* @static
* @desc Creates an action that deletes user's submission to a challenge.
* @param {String} tokenV3 Topcoder v3 auth token.
* @param {String} tokenV5 Topcoder v5 auth token.
* @param {Number|String} submissionId Submission ID.
* @return {Action}
*/
function deleteSubmissionDone(tokenV3, submissionId) {
return getApi('V3', tokenV3).delete(`/submissions/${submissionId}`)
.then(() => submissionId);
function deleteSubmissionDone(tokenV5, submissionId) {
const submissionsService = getSubmissionService(tokenV5);
const filters = { legacySubmissionId: submissionId };

// from the legacy submissionId first get the GUID of the submission
// and pass that id to the V5 api
return submissionsService.getSubmissions(filters, {})
.then((submissions) => {
if (submissions.length === 0) {
throw new Error(`Submission ${submissionId} does not exist.`);
}
return getApi('V5', tokenV5).delete(`/submissions/${submissions[0].id}`)
.then(res => (res.ok ? submissionId : new Error(res.statusText)))
.then(res => res);
});
}

/**
Expand Down