@stackfactor/client-api 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/learningContent.js +255 -0
- package/package.json +1 -1
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
const { axios } = require("./axios");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
axios: axios,
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create learning content and set information
|
|
8
|
+
* @param {Object} data Learning content data
|
|
9
|
+
* @param {String} token Authorization token
|
|
10
|
+
* @returns {Promise<Object>} The created learning content
|
|
11
|
+
*/
|
|
12
|
+
createLearningContent: (data, token) => {
|
|
13
|
+
return new Promise(function (resolve, reject) {
|
|
14
|
+
const requestData = {
|
|
15
|
+
data: data,
|
|
16
|
+
};
|
|
17
|
+
let confirmationRequest = axios.put(
|
|
18
|
+
"api/v1/learningcontent",
|
|
19
|
+
requestData,
|
|
20
|
+
{ headers: { authorization: token } }
|
|
21
|
+
);
|
|
22
|
+
confirmationRequest
|
|
23
|
+
.then((response) => {
|
|
24
|
+
resolve(response.data);
|
|
25
|
+
})
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
reject(error);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Delete learning content
|
|
34
|
+
* @param {String} id The id of the learning content to be deleted
|
|
35
|
+
* @param {String} comment The comment included with the deletion
|
|
36
|
+
* @param {String} token Authorization token
|
|
37
|
+
* @returns {Promise<Object>} The response from the server
|
|
38
|
+
*/
|
|
39
|
+
deleteLearningContent: (id, comment, token) => {
|
|
40
|
+
const data = {
|
|
41
|
+
id: id,
|
|
42
|
+
};
|
|
43
|
+
if (comment) data.comment = comment;
|
|
44
|
+
return new Promise(function (resolve, reject) {
|
|
45
|
+
const request = axios.delete(`api/v1/learningcontent/`, {
|
|
46
|
+
headers: { authorization: token },
|
|
47
|
+
data: data,
|
|
48
|
+
});
|
|
49
|
+
request
|
|
50
|
+
.then((response) => {
|
|
51
|
+
resolve(response.data);
|
|
52
|
+
})
|
|
53
|
+
.catch((error) => {
|
|
54
|
+
reject(error);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Discard the learning content draft changes
|
|
61
|
+
* @param {String} id The id of the learning content to be deleted
|
|
62
|
+
* @param {String} token Authorization token
|
|
63
|
+
* @returns {Promise<Object>} The response from the server
|
|
64
|
+
*/
|
|
65
|
+
discardLearningContentChanges: (id, token) => {
|
|
66
|
+
return new Promise(function (resolve, reject) {
|
|
67
|
+
const data = {};
|
|
68
|
+
const request = axios.get(`api/v1/learningcontent/discard/${id}`, {
|
|
69
|
+
headers: { authorization: token },
|
|
70
|
+
data: data,
|
|
71
|
+
});
|
|
72
|
+
request
|
|
73
|
+
.then((response) => {
|
|
74
|
+
resolve(response.data);
|
|
75
|
+
})
|
|
76
|
+
.catch((error) => {
|
|
77
|
+
reject(error);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Get the learning content information by id
|
|
84
|
+
* @param {String} id The id of the learning content
|
|
85
|
+
* @param {String} version The version of the learning content
|
|
86
|
+
* @param {String} token Authorization token
|
|
87
|
+
* @returns {Promise<Object>} The response from the server
|
|
88
|
+
*/
|
|
89
|
+
getLearningContentInformationById: (id, version, token) => {
|
|
90
|
+
return new Promise(function (resolve, reject) {
|
|
91
|
+
let confirmationRequest = axios.get(
|
|
92
|
+
`api/v1/learningcontent/${id}/${version}`,
|
|
93
|
+
{
|
|
94
|
+
headers: { authorization: token },
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
confirmationRequest
|
|
98
|
+
.then((response) => {
|
|
99
|
+
resolve(response.data);
|
|
100
|
+
})
|
|
101
|
+
.catch((error) => {
|
|
102
|
+
reject(error);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Get the list of available content types
|
|
109
|
+
* @param {Array<String>} filter The filter used to select the learning content
|
|
110
|
+
* @param {String} version The version to be retrieved
|
|
111
|
+
* @param {boolean} includeDeleted When true it will return the deleted records as well
|
|
112
|
+
* @param {String} token Authorization token
|
|
113
|
+
* @returns {Promise<Array<Object>>} The list of available content
|
|
114
|
+
*/
|
|
115
|
+
getLearningContentList: (filter, version, includeDeleted, token) => {
|
|
116
|
+
return new Promise(function (resolve, reject) {
|
|
117
|
+
const requestData = {
|
|
118
|
+
version: version,
|
|
119
|
+
includeDeleted: includeDeleted,
|
|
120
|
+
};
|
|
121
|
+
if (filter) requestData.filter = filter;
|
|
122
|
+
let confirmationRequest = axios.post(
|
|
123
|
+
`api/v1/learningcontent`,
|
|
124
|
+
requestData,
|
|
125
|
+
{
|
|
126
|
+
headers: { authorization: token },
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
confirmationRequest
|
|
130
|
+
.then((response) => {
|
|
131
|
+
resolve(response.data);
|
|
132
|
+
})
|
|
133
|
+
.catch((error) => {
|
|
134
|
+
reject(error);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Publish learning content
|
|
141
|
+
* @param {String} id The id of the content to be published
|
|
142
|
+
* @param {String} comment The comment to be include with the request
|
|
143
|
+
* @param {String} token Authorization token
|
|
144
|
+
* @returns {Promise<Object>} The response from the server
|
|
145
|
+
*/
|
|
146
|
+
publishLearningContent: (id, comment, token) => {
|
|
147
|
+
return new Promise(function (resolve, reject) {
|
|
148
|
+
let data = {};
|
|
149
|
+
if (comment) data.comment = comment;
|
|
150
|
+
|
|
151
|
+
let confirmationRequest = axios.post(
|
|
152
|
+
`api/v1/learningcontent/publish/${id}`,
|
|
153
|
+
data,
|
|
154
|
+
{
|
|
155
|
+
headers: { authorization: token },
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
confirmationRequest
|
|
159
|
+
.then((response) => {
|
|
160
|
+
resolve(response.data);
|
|
161
|
+
})
|
|
162
|
+
.catch((error) => {
|
|
163
|
+
reject(error);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Set learning content information
|
|
170
|
+
* @param {String} id The id of the learning content to be updated
|
|
171
|
+
* @param {Object} data Data used to update the learning content
|
|
172
|
+
* @param {String} token Authorization token
|
|
173
|
+
* @returns {Promise<Object>} The updated learning content
|
|
174
|
+
*/
|
|
175
|
+
setLearningContentInformation: (id, data, token) => {
|
|
176
|
+
return new Promise(function (resolve, reject) {
|
|
177
|
+
const requestData = {
|
|
178
|
+
data: data,
|
|
179
|
+
id: id,
|
|
180
|
+
};
|
|
181
|
+
let confirmationRequest = axios.post(
|
|
182
|
+
`api/v1/learningcontent/update`,
|
|
183
|
+
requestData,
|
|
184
|
+
{
|
|
185
|
+
headers: { authorization: token },
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
confirmationRequest
|
|
189
|
+
.then((response) => {
|
|
190
|
+
resolve(response.data);
|
|
191
|
+
})
|
|
192
|
+
.catch((error) => {
|
|
193
|
+
reject(error);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Update the learning content tags
|
|
200
|
+
* @param {String} id The id of the learning to be updated
|
|
201
|
+
* @param {Object} tags Updated learning content tags
|
|
202
|
+
* @param {String} token Authorization token
|
|
203
|
+
*/
|
|
204
|
+
setLearningContentTags: (id, tags, token) => {
|
|
205
|
+
return new Promise(function (resolve, reject) {
|
|
206
|
+
const requestData = {
|
|
207
|
+
tags: tags,
|
|
208
|
+
id: id,
|
|
209
|
+
};
|
|
210
|
+
let confirmationRequest = axios.post(
|
|
211
|
+
`api/v1/learningcontent/updatetags/`,
|
|
212
|
+
requestData,
|
|
213
|
+
{
|
|
214
|
+
headers: { authorization: token },
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
confirmationRequest
|
|
218
|
+
.then((response) => {
|
|
219
|
+
resolve(response.data);
|
|
220
|
+
})
|
|
221
|
+
.catch((error) => {
|
|
222
|
+
reject(error);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Watch learning content
|
|
229
|
+
* @param {String} id The id of the learning content to be updated
|
|
230
|
+
* @param {Boolean} watch Set to true or false
|
|
231
|
+
* @param {String} token Authorization token
|
|
232
|
+
*/
|
|
233
|
+
watchLearningContent: (id, watch, token) => {
|
|
234
|
+
return new Promise(function (resolve, reject) {
|
|
235
|
+
const requestData = {
|
|
236
|
+
id: id,
|
|
237
|
+
watch: watch,
|
|
238
|
+
};
|
|
239
|
+
let confirmationRequest = axios.post(
|
|
240
|
+
`api/v1/learningcontent/watch`,
|
|
241
|
+
requestData,
|
|
242
|
+
{
|
|
243
|
+
headers: { authorization: token },
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
confirmationRequest
|
|
247
|
+
.then((response) => {
|
|
248
|
+
resolve(response.data);
|
|
249
|
+
})
|
|
250
|
+
.catch((error) => {
|
|
251
|
+
reject(error);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
},
|
|
255
|
+
};
|