Merge pull request #17583 from edx/MLoTurco/learner-3925-feature-client-api

Add Client API

Learner-3925
Learner-4388
This commit is contained in:
Michael LoTurco
2018-03-08 14:17:14 -05:00
committed by GitHub
3 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import 'whatwg-fetch';
import Cookies from 'js-cookie';
import { entitlementApi } from './endpoints';
const HEADERS = {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-CSRFToken': Cookies.get('csrftoken'),
};
const requestEntitlements = ({ username }) => fetch(
`${entitlementApi}/?user=${username}`, {
credentials: 'same-origin',
method: 'get',
},
);
const createEntitlement = ({ username, courseUuid, mode, action, comments }) => fetch(
`${entitlementApi}`, {
credentials: 'same-origin',
method: 'post',
headers: HEADERS,
body: JSON.stringify({
course_uuid: courseUuid,
user: username,
mode,
support_details: [{
action,
comments,
}],
}),
},
);
const updateEntitlement = ({ entitlementUuid, unenrolledRun, action, comments }) => fetch(
`${entitlementApi}/${entitlementUuid}`, {
credentials: 'same-origin',
method: 'patch',
headers: HEADERS,
body: JSON.stringify({
expired_at: null,
enrollment_run: null,
support_details: [{
unenrolled_run: unenrolledRun,
action,
comments,
}],
}),
},
);
export {
requestEntitlements,
createEntitlement,
updateEntitlement,
};

View File

@@ -0,0 +1,5 @@
const entitlementApi = '/api/entitlements/v1/entitlements';
export {
entitlementApi,
};

View File

@@ -32,6 +32,7 @@
"jquery": "2.2.4",
"jquery-migrate": "1.4.1",
"jquery.scrollto": "2.1.2",
"js-cookie": "2.2.0",
"moment": "2.18.1",
"moment-timezone": "0.5.14",
"node-sass": "4.7.2",
@@ -53,6 +54,7 @@
"webpack": "2.7.0",
"webpack-bundle-tracker": "0.2.1",
"webpack-merge": "4.1.1",
"whatwg-fetch": "2.0.3",
"which-country": "1.0.0"
},
"devDependencies": {