musora-content-services 1.2.4 → 1.3.1
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/.prettierignore +5 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +11 -0
- package/babel.config.cjs +1 -1
- package/jest.config.js +9 -10
- package/jsdoc.json +17 -12
- package/package.json +2 -1
- package/src/contentMetaData.js +1190 -1131
- package/src/contentTypeConfig.js +492 -387
- package/src/filterBuilder.js +163 -145
- package/src/index.d.ts +227 -237
- package/src/index.js +226 -236
- package/src/services/config.js +12 -12
- package/src/services/contentLikes.js +33 -32
- package/src/services/contentProgress.js +233 -200
- package/src/services/dataContext.js +99 -93
- package/src/services/lastUpdated.js +7 -7
- package/src/services/railcontent.js +368 -364
- package/src/services/sanity.js +975 -955
- package/src/services/userPermissions.js +12 -14
- package/test/contentLikes.test.js +89 -86
- package/test/contentProgress.test.js +229 -236
- package/test/initializeTests.js +54 -51
- package/test/lastUpdated.test.js +20 -18
- package/test/live/contentProgressLive.test.js +135 -137
- package/test/live/railcontentLive.test.js +12 -14
- package/test/localStorageMock.js +16 -16
- package/test/log.js +5 -5
- package/test/sanityQueryService.test.js +857 -821
- package/test/userPermissions.test.js +15 -15
- package/tools/generate-index.cjs +108 -111
- package/.yarnrc.yml +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Railcontent-Services
|
|
3
3
|
*/
|
|
4
|
-
import {contentStatusCompleted} from
|
|
4
|
+
import { contentStatusCompleted } from './contentProgress.js'
|
|
5
5
|
|
|
6
|
-
import { globalConfig } from
|
|
6
|
+
import { globalConfig } from './config.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Exported functions that are excluded from index generation.
|
|
@@ -11,17 +11,17 @@ import { globalConfig } from "./config.js";
|
|
|
11
11
|
* @type {string[]}
|
|
12
12
|
*/
|
|
13
13
|
const excludeFromGeneratedIndex = [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
let challengeIndexMetaDataPromise = null
|
|
14
|
+
'fetchUserLikes',
|
|
15
|
+
'postContentLiked',
|
|
16
|
+
'postContentUnliked',
|
|
17
|
+
'postRecordWatchSession',
|
|
18
|
+
'postContentStarted',
|
|
19
|
+
'postContentCompleted',
|
|
20
|
+
'postContentReset',
|
|
21
|
+
'fetchUserPermissionsData',
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
let challengeIndexMetaDataPromise = null
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Fetches the completion status of a specific lesson for the current user.
|
|
@@ -34,30 +34,29 @@ let challengeIndexMetaDataPromise = null;
|
|
|
34
34
|
* .catch(error => console.error(error));
|
|
35
35
|
*/
|
|
36
36
|
export async function fetchCompletedState(content_id) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
} catch (error) {
|
|
55
|
-
console.error('Fetch error:', error);
|
|
56
|
-
return null;
|
|
37
|
+
const url = `/content/user_progress/${globalConfig.railcontentConfig.userId}?content_ids[]=${content_id}`
|
|
38
|
+
|
|
39
|
+
const headers = {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
Accept: 'application/json',
|
|
42
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const response = await fetchAbsolute(url, { headers })
|
|
47
|
+
const result = await response.json()
|
|
48
|
+
|
|
49
|
+
if (result && result[content_id]) {
|
|
50
|
+
return result[content_id] // Return the correct object
|
|
51
|
+
} else {
|
|
52
|
+
return null // Handle unexpected structure
|
|
57
53
|
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Fetch error:', error)
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
61
60
|
/**
|
|
62
61
|
* Fetches the completion status for multiple songs for the current user.
|
|
63
62
|
*
|
|
@@ -69,26 +68,26 @@ export async function fetchCompletedState(content_id) {
|
|
|
69
68
|
* .catch(error => console.error(error));
|
|
70
69
|
*/
|
|
71
70
|
export async function fetchAllCompletedStates(contentIds) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.error('Fetch error:', error);
|
|
90
|
-
return null;
|
|
71
|
+
const url = `/content/user_progress/${globalConfig.railcontentConfig.userId}?${contentIds.map((id) => `content_ids[]=${id}`).join('&')}`
|
|
72
|
+
|
|
73
|
+
const headers = {
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
Accept: 'application/json',
|
|
76
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const response = await fetchAbsolute(url, { headers })
|
|
81
|
+
const result = await response.json()
|
|
82
|
+
if (result) {
|
|
83
|
+
return result
|
|
84
|
+
} else {
|
|
85
|
+
console.log('result not json')
|
|
91
86
|
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Fetch error:', error)
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
/**
|
|
@@ -102,27 +101,27 @@ export async function fetchAllCompletedStates(contentIds) {
|
|
|
102
101
|
* .catch(error => console.error(error));
|
|
103
102
|
*/
|
|
104
103
|
export async function fetchSongsInProgress(brand) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error('Fetch error:', error);
|
|
124
|
-
return null;
|
|
104
|
+
const url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?content_type=song&brand=${brand}`
|
|
105
|
+
|
|
106
|
+
const headers = {
|
|
107
|
+
'Content-Type': 'application/json',
|
|
108
|
+
Accept: 'application/json',
|
|
109
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const response = await fetchAbsolute(url, { headers })
|
|
114
|
+
const result = await response.json()
|
|
115
|
+
if (result) {
|
|
116
|
+
//console.log('fetchSongsInProgress', result);
|
|
117
|
+
return result
|
|
118
|
+
} else {
|
|
119
|
+
console.log('result not json')
|
|
125
120
|
}
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error('Fetch error:', error)
|
|
123
|
+
return null
|
|
124
|
+
}
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
/**
|
|
@@ -138,34 +137,34 @@ export async function fetchSongsInProgress(brand) {
|
|
|
138
137
|
* .then(songs => console.log(songs))
|
|
139
138
|
* .catch(error => console.error(error));
|
|
140
139
|
*/
|
|
141
|
-
export async function fetchContentInProgress(type =
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
export async function fetchContentInProgress(type = 'all', brand, { page, limit } = {}) {
|
|
141
|
+
let url
|
|
142
|
+
const limitString = limit ? `&limit=${limit}` : ''
|
|
143
|
+
const pageString = page ? `&page=${page}` : ''
|
|
144
|
+
|
|
145
|
+
if (type === 'all') {
|
|
146
|
+
url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?brand=${brand}${limitString}${pageString}`
|
|
147
|
+
} else {
|
|
148
|
+
url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?content_type=${type}&brand=${brand}${limitString}${pageString}`
|
|
149
|
+
}
|
|
150
|
+
const headers = {
|
|
151
|
+
'Content-Type': 'application/json',
|
|
152
|
+
Accept: 'application/json',
|
|
153
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const response = await fetchAbsolute(url, { headers })
|
|
157
|
+
const result = await response.json()
|
|
158
|
+
if (result) {
|
|
159
|
+
//console.log('contentInProgress', result);
|
|
160
|
+
return result
|
|
148
161
|
} else {
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
const headers = {
|
|
152
|
-
'Content-Type': 'application/json',
|
|
153
|
-
'Accept': 'application/json',
|
|
154
|
-
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
155
|
-
};
|
|
156
|
-
try {
|
|
157
|
-
const response = await fetchAbsolute(url, {headers});
|
|
158
|
-
const result = await response.json();
|
|
159
|
-
if (result) {
|
|
160
|
-
//console.log('contentInProgress', result);
|
|
161
|
-
return result;
|
|
162
|
-
} else {
|
|
163
|
-
console.log('result not json');
|
|
164
|
-
}
|
|
165
|
-
} catch (error) {
|
|
166
|
-
console.error('Fetch error:', error);
|
|
167
|
-
return null;
|
|
162
|
+
console.log('result not json')
|
|
168
163
|
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error('Fetch error:', error)
|
|
166
|
+
return null
|
|
167
|
+
}
|
|
169
168
|
}
|
|
170
169
|
|
|
171
170
|
/**
|
|
@@ -181,37 +180,36 @@ export async function fetchContentInProgress(type = "all", brand, {page, limit}
|
|
|
181
180
|
* .then(songs => console.log(songs))
|
|
182
181
|
* .catch(error => console.error(error));
|
|
183
182
|
*/
|
|
184
|
-
export async function fetchCompletedContent(type =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
183
|
+
export async function fetchCompletedContent(type = 'all', brand, { page, limit } = {}) {
|
|
184
|
+
let url
|
|
185
|
+
const limitString = limit ? `&limit=${limit}` : ''
|
|
186
|
+
const pageString = page ? `&page=${page}` : ''
|
|
187
|
+
|
|
188
|
+
if (type === 'all') {
|
|
189
|
+
url = `/content/completed/${globalConfig.railcontentConfig.userId}?brand=${brand}${limitString}${pageString}`
|
|
190
|
+
} else {
|
|
191
|
+
url = `/content/completed/${globalConfig.railcontentConfig.userId}?content_type=${type}&brand=${brand}${limitString}${pageString}`
|
|
192
|
+
}
|
|
193
|
+
const headers = {
|
|
194
|
+
'Content-Type': 'application/json',
|
|
195
|
+
Accept: 'application/json',
|
|
196
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const response = await fetchAbsolute(url, { headers })
|
|
200
|
+
const result = await response.json()
|
|
201
|
+
if (result) {
|
|
202
|
+
//console.log('completed content', result);
|
|
203
|
+
return result
|
|
191
204
|
} else {
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
const headers = {
|
|
195
|
-
'Content-Type': 'application/json',
|
|
196
|
-
'Accept': 'application/json',
|
|
197
|
-
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
198
|
-
};
|
|
199
|
-
try {
|
|
200
|
-
const response = await fetchAbsolute(url, {headers});
|
|
201
|
-
const result = await response.json();
|
|
202
|
-
if (result) {
|
|
203
|
-
//console.log('completed content', result);
|
|
204
|
-
return result;
|
|
205
|
-
} else {
|
|
206
|
-
console.log('result not json');
|
|
207
|
-
}
|
|
208
|
-
} catch (error) {
|
|
209
|
-
console.error('Fetch error:', error);
|
|
210
|
-
return null;
|
|
205
|
+
console.log('result not json')
|
|
211
206
|
}
|
|
207
|
+
} catch (error) {
|
|
208
|
+
console.error('Fetch error:', error)
|
|
209
|
+
return null
|
|
210
|
+
}
|
|
212
211
|
}
|
|
213
212
|
|
|
214
|
-
|
|
215
213
|
/**
|
|
216
214
|
* Fetches user context data for a specific piece of content.
|
|
217
215
|
*
|
|
@@ -223,26 +221,26 @@ export async function fetchCompletedContent(type = "all", brand, {page, limit} =
|
|
|
223
221
|
* .catch(error => console.error(error));
|
|
224
222
|
*/
|
|
225
223
|
export async function fetchContentPageUserData(contentId) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
} catch (error) {
|
|
243
|
-
console.error('Fetch error:', error);
|
|
244
|
-
return null;
|
|
224
|
+
let url = `/content/${contentId}/user_data/${globalConfig.railcontentConfig.userId}`
|
|
225
|
+
const headers = {
|
|
226
|
+
'Content-Type': 'application/json',
|
|
227
|
+
Accept: 'application/json',
|
|
228
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
const response = await fetchAbsolute(url, { headers })
|
|
233
|
+
const result = await response.json()
|
|
234
|
+
if (result) {
|
|
235
|
+
console.log('fetchContentPageUserData', result)
|
|
236
|
+
return result
|
|
237
|
+
} else {
|
|
238
|
+
console.log('result not json')
|
|
245
239
|
}
|
|
240
|
+
} catch (error) {
|
|
241
|
+
console.error('Fetch error:', error)
|
|
242
|
+
return null
|
|
243
|
+
}
|
|
246
244
|
}
|
|
247
245
|
|
|
248
246
|
/**
|
|
@@ -252,123 +250,130 @@ export async function fetchContentPageUserData(contentId) {
|
|
|
252
250
|
* @returns {Promise<Object|null>} - Returns and Object with the id and type of the next piece of content if found, otherwise null.
|
|
253
251
|
*/
|
|
254
252
|
export async function fetchNextContentDataForParent(contentId) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
} catch (error) {
|
|
272
|
-
console.error('Fetch error:', error);
|
|
273
|
-
return null;
|
|
253
|
+
let url = `/content/${contentId}/next/${globalConfig.railcontentConfig.userId}`
|
|
254
|
+
const headers = {
|
|
255
|
+
'Content-Type': 'application/json',
|
|
256
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
const response = await fetchAbsolute(url, { headers })
|
|
261
|
+
const result = await response.json()
|
|
262
|
+
if (result) {
|
|
263
|
+
// console.log('fetchNextContentDataForParent', result);
|
|
264
|
+
return result.next
|
|
265
|
+
} else {
|
|
266
|
+
console.log('fetchNextContentDataForParent result not json')
|
|
267
|
+
return null
|
|
274
268
|
}
|
|
269
|
+
} catch (error) {
|
|
270
|
+
console.error('Fetch error:', error)
|
|
271
|
+
return null
|
|
272
|
+
}
|
|
275
273
|
}
|
|
276
274
|
|
|
277
|
-
|
|
278
275
|
export async function fetchUserPermissionsData() {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
276
|
+
let url = `/content/user/permissions`
|
|
277
|
+
// in the case of an unauthorized user, we return empty permissions
|
|
278
|
+
return (await fetchHandler(url, 'get')) ?? []
|
|
282
279
|
}
|
|
283
280
|
|
|
284
|
-
async function fetchDataHandler(url, dataVersion, method =
|
|
285
|
-
|
|
281
|
+
async function fetchDataHandler(url, dataVersion, method = 'get') {
|
|
282
|
+
return fetchHandler(url, method, dataVersion)
|
|
286
283
|
}
|
|
287
284
|
|
|
288
285
|
async function postDataHandler(url, data) {
|
|
289
|
-
|
|
286
|
+
return fetchHandler(url, 'post', null, data)
|
|
290
287
|
}
|
|
291
288
|
|
|
292
289
|
async function patchDataHandler(url, data) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
export async function fetchHandler(url, method = "get", dataVersion = null, body = null) {
|
|
296
|
-
let headers = {
|
|
297
|
-
'Content-Type': 'application/json',
|
|
298
|
-
'Accept': 'application/json',
|
|
299
|
-
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
if (!globalConfig.isMA) {
|
|
303
|
-
const params = new URLSearchParams(window.location.search);
|
|
304
|
-
if (params.get('testNow')) {
|
|
305
|
-
headers['testNow'] = params.get('testNow');
|
|
306
|
-
}
|
|
307
|
-
if (params.get('timezone')) {
|
|
308
|
-
headers['M-Client-Timezone'] = params.get('timezone');
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
if (globalConfig.localTimezoneString) {
|
|
313
|
-
headers['M-Client-Timezone'] = globalConfig.localTimezoneString;
|
|
314
|
-
}
|
|
290
|
+
return fetchHandler(url, 'patch', null, data)
|
|
291
|
+
}
|
|
315
292
|
|
|
316
|
-
|
|
317
|
-
|
|
293
|
+
export async function fetchHandler(url, method = 'get', dataVersion = null, body = null) {
|
|
294
|
+
let headers = {
|
|
295
|
+
'Content-Type': 'application/json',
|
|
296
|
+
Accept: 'application/json',
|
|
297
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (!globalConfig.isMA) {
|
|
301
|
+
const params = new URLSearchParams(window.location.search)
|
|
302
|
+
if (params.get('testNow')) {
|
|
303
|
+
headers['testNow'] = params.get('testNow')
|
|
318
304
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const options = {
|
|
322
|
-
method,
|
|
323
|
-
headers,
|
|
324
|
-
};
|
|
325
|
-
if (body) {
|
|
326
|
-
options.body = JSON.stringify(body);
|
|
305
|
+
if (params.get('timezone')) {
|
|
306
|
+
headers['M-Client-Timezone'] = params.get('timezone')
|
|
327
307
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (globalConfig.localTimezoneString) {
|
|
311
|
+
headers['M-Client-Timezone'] = globalConfig.localTimezoneString
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (globalConfig.railcontentConfig.authToken) {
|
|
315
|
+
headers['Authorization'] = `Bearer ${globalConfig.railcontentConfig.authToken}`
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (dataVersion) headers['Data-Version'] = dataVersion
|
|
319
|
+
const options = {
|
|
320
|
+
method,
|
|
321
|
+
headers,
|
|
322
|
+
}
|
|
323
|
+
if (body) {
|
|
324
|
+
options.body = JSON.stringify(body)
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
const response = await fetchAbsolute(url, options)
|
|
328
|
+
if (response.ok) {
|
|
329
|
+
return await response.json()
|
|
330
|
+
} else {
|
|
331
|
+
console.error(`Fetch error: ${method} ${url} ${response.status} ${response.statusText}`)
|
|
332
|
+
console.log(response)
|
|
338
333
|
}
|
|
339
|
-
|
|
334
|
+
} catch (error) {
|
|
335
|
+
console.error('Fetch error:', error)
|
|
336
|
+
}
|
|
337
|
+
return null
|
|
340
338
|
}
|
|
341
339
|
|
|
342
340
|
export async function fetchUserLikes(currentVersion) {
|
|
343
|
-
|
|
344
|
-
|
|
341
|
+
let url = `/content/user/likes/all`
|
|
342
|
+
return fetchDataHandler(url, currentVersion)
|
|
345
343
|
}
|
|
346
344
|
|
|
347
345
|
export async function postContentLiked(contentId) {
|
|
348
|
-
|
|
349
|
-
|
|
346
|
+
let url = `/content/user/likes/like/${contentId}`
|
|
347
|
+
return await postDataHandler(url)
|
|
350
348
|
}
|
|
351
349
|
|
|
352
350
|
export async function postContentUnliked(contentId) {
|
|
353
|
-
|
|
354
|
-
|
|
351
|
+
let url = `/content/user/likes/unlike/${contentId}`
|
|
352
|
+
return await postDataHandler(url)
|
|
355
353
|
}
|
|
356
354
|
|
|
357
355
|
export async function fetchContentProgress(currentVersion) {
|
|
358
|
-
|
|
359
|
-
|
|
356
|
+
let url = `/content/user/progress/all`
|
|
357
|
+
return fetchDataHandler(url, currentVersion)
|
|
360
358
|
}
|
|
361
359
|
|
|
362
|
-
export async function postRecordWatchSession(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
360
|
+
export async function postRecordWatchSession(
|
|
361
|
+
contentId,
|
|
362
|
+
mediaTypeId,
|
|
363
|
+
mediaLengthSeconds,
|
|
364
|
+
currentSeconds,
|
|
365
|
+
secondsPlayed,
|
|
366
|
+
sessionId
|
|
367
|
+
) {
|
|
368
|
+
let url = `/railtracker/v2/media-playback-session`
|
|
369
|
+
return postDataHandler(url, {
|
|
370
|
+
content_id: contentId,
|
|
371
|
+
media_type_id: mediaTypeId,
|
|
372
|
+
media_length_seconds: mediaLengthSeconds,
|
|
373
|
+
current_second: currentSeconds,
|
|
374
|
+
seconds_played: secondsPlayed,
|
|
375
|
+
session_id: sessionId,
|
|
376
|
+
})
|
|
372
377
|
}
|
|
373
378
|
|
|
374
379
|
/**
|
|
@@ -378,8 +383,8 @@ export async function postRecordWatchSession(contentId, mediaTypeId, mediaLength
|
|
|
378
383
|
* @returns {Promise<any|null>}
|
|
379
384
|
*/
|
|
380
385
|
export async function fetchChallengeMetadata(contentId) {
|
|
381
|
-
|
|
382
|
-
|
|
386
|
+
let url = `/challenges/${contentId}`
|
|
387
|
+
return await fetchHandler(url, 'get')
|
|
383
388
|
}
|
|
384
389
|
|
|
385
390
|
/**
|
|
@@ -389,11 +394,10 @@ export async function fetchChallengeMetadata(contentId) {
|
|
|
389
394
|
* @returns {Promise<any|null>}
|
|
390
395
|
*/
|
|
391
396
|
export async function fetchChallengeLessonData(contentId) {
|
|
392
|
-
|
|
393
|
-
|
|
397
|
+
let url = `/challenges/lessons/${contentId}`
|
|
398
|
+
return await fetchHandler(url, 'get')
|
|
394
399
|
}
|
|
395
400
|
|
|
396
|
-
|
|
397
401
|
/**
|
|
398
402
|
* Fetch all owned brand challenges for user
|
|
399
403
|
* @param {string|null} brand - brand
|
|
@@ -402,10 +406,10 @@ export async function fetchChallengeLessonData(contentId) {
|
|
|
402
406
|
* @returns {Promise<any|null>}
|
|
403
407
|
*/
|
|
404
408
|
export async function fetchOwnedChallenges(brand = null, page, limit) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
+
let brandParam = brand ? `&brand=${brand}` : ''
|
|
410
|
+
let pageAndLimit = `?page=${page}&limit=${limit}`
|
|
411
|
+
let url = `/challenges/tab_owned/get${pageAndLimit}${brandParam}`
|
|
412
|
+
return await fetchHandler(url, 'get')
|
|
409
413
|
}
|
|
410
414
|
|
|
411
415
|
/**
|
|
@@ -416,13 +420,12 @@ export async function fetchOwnedChallenges(brand = null, page, limit) {
|
|
|
416
420
|
* @returns {Promise<any|null>}
|
|
417
421
|
*/
|
|
418
422
|
export async function fetchCompletedChallenges(brand = null, page, limit) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
+
let brandParam = brand ? `&brand=${brand}` : ''
|
|
424
|
+
let pageAndLimit = `?page=${page}&limit=${limit}`
|
|
425
|
+
let url = `/challenges/tab_completed/get${pageAndLimit}${brandParam}`
|
|
426
|
+
return await fetchHandler(url, 'get')
|
|
423
427
|
}
|
|
424
428
|
|
|
425
|
-
|
|
426
429
|
/**
|
|
427
430
|
* Fetch challenge, lesson, and user metadata for a given challenge
|
|
428
431
|
*
|
|
@@ -430,8 +433,8 @@ export async function fetchCompletedChallenges(brand = null, page, limit) {
|
|
|
430
433
|
* @returns {Promise<any|null>}
|
|
431
434
|
*/
|
|
432
435
|
export async function fetchUserChallengeProgress(contentId) {
|
|
433
|
-
|
|
434
|
-
|
|
436
|
+
let url = `/challenges/user_data/${contentId}`
|
|
437
|
+
return await fetchHandler(url, 'get')
|
|
435
438
|
}
|
|
436
439
|
|
|
437
440
|
/**
|
|
@@ -441,8 +444,8 @@ export async function fetchUserChallengeProgress(contentId) {
|
|
|
441
444
|
* @returns {Promise<any|null>} - streamed PDF
|
|
442
445
|
*/
|
|
443
446
|
export async function fetchUserAward(contentId) {
|
|
444
|
-
|
|
445
|
-
|
|
447
|
+
let url = `/challenges/download_award/${contentId}`
|
|
448
|
+
return await fetchHandler(url, 'get')
|
|
446
449
|
}
|
|
447
450
|
|
|
448
451
|
/**
|
|
@@ -453,35 +456,34 @@ export async function fetchUserAward(contentId) {
|
|
|
453
456
|
* @returns {Promise<any|null>}
|
|
454
457
|
*/
|
|
455
458
|
export async function fetchChallengeIndexMetadata(contentIds) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
459
|
+
if (!challengeIndexMetaDataPromise) {
|
|
460
|
+
challengeIndexMetaDataPromise = getChallengeIndexMetadataPromise()
|
|
461
|
+
}
|
|
462
|
+
let results = await challengeIndexMetaDataPromise
|
|
463
|
+
if (Array.isArray(contentIds)) {
|
|
464
|
+
results = results.filter(function (challenge) {
|
|
465
|
+
return contentIds.includes(challenge.content_id)
|
|
466
|
+
})
|
|
467
|
+
}
|
|
468
|
+
return results
|
|
466
469
|
}
|
|
467
470
|
|
|
468
471
|
async function getChallengeIndexMetadataPromise() {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
472
|
+
let url = `/challenges/user_progress_for_index_page/get`
|
|
473
|
+
const result = await fetchHandler(url, 'get')
|
|
474
|
+
challengeIndexMetaDataPromise = null
|
|
475
|
+
return result
|
|
473
476
|
}
|
|
474
477
|
|
|
475
|
-
|
|
476
478
|
/**
|
|
477
479
|
* Get active brand challenges for the authorized user
|
|
478
480
|
*
|
|
479
481
|
* @returns {Promise<any|null>}
|
|
480
482
|
*/
|
|
481
483
|
export async function fetchChallengeUserActiveChallenges(brand = null) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
484
|
+
let brandParam = brand ? `?brand=${brand}` : ''
|
|
485
|
+
let url = `/challenges/user_active_challenges/get${brandParam}`
|
|
486
|
+
return await fetchHandler(url, 'get')
|
|
485
487
|
}
|
|
486
488
|
|
|
487
489
|
/**
|
|
@@ -490,9 +492,9 @@ export async function fetchChallengeUserActiveChallenges(brand = null) {
|
|
|
490
492
|
* @returns {Promise<any|null>}
|
|
491
493
|
*/
|
|
492
494
|
export async function fetchCarouselCardData(brand = null) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
495
|
+
const brandParam = brand ? `?brand=${brand}` : ''
|
|
496
|
+
let url = `/api/v1/content/carousel${brandParam}`
|
|
497
|
+
return await fetchHandler(url, 'get')
|
|
496
498
|
}
|
|
497
499
|
|
|
498
500
|
/**
|
|
@@ -502,9 +504,9 @@ export async function fetchCarouselCardData(brand = null) {
|
|
|
502
504
|
* @returns {Promise<any|null>}
|
|
503
505
|
*/
|
|
504
506
|
export async function fetchUserBadges(brand = null) {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
507
|
+
let brandParam = brand ? `?brand=${brand}` : ''
|
|
508
|
+
let url = `/challenges/user_badges/get${brandParam}`
|
|
509
|
+
return await fetchHandler(url, 'get')
|
|
508
510
|
}
|
|
509
511
|
|
|
510
512
|
/**
|
|
@@ -516,8 +518,8 @@ export async function fetchUserBadges(brand = null) {
|
|
|
516
518
|
* @returns {Promise<any|null>}
|
|
517
519
|
*/
|
|
518
520
|
export async function postChallengesSetStartDate(contentId, startDate) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
+
let url = `/challenges/set_start_date/${contentId}?start_date=${startDate}`
|
|
522
|
+
return await fetchHandler(url, 'post')
|
|
521
523
|
}
|
|
522
524
|
|
|
523
525
|
/**
|
|
@@ -528,8 +530,8 @@ export async function postChallengesSetStartDate(contentId, startDate) {
|
|
|
528
530
|
* @returns {Promise<any|null>}
|
|
529
531
|
*/
|
|
530
532
|
export async function postChallengesUnlock(contentId) {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
+
let url = `/challenges/unlock/${contentId}`
|
|
534
|
+
return await fetchHandler(url, 'post')
|
|
533
535
|
}
|
|
534
536
|
|
|
535
537
|
/**
|
|
@@ -540,8 +542,8 @@ export async function postChallengesUnlock(contentId) {
|
|
|
540
542
|
* @returns {Promise<any|null>}
|
|
541
543
|
*/
|
|
542
544
|
export async function postChallengesEnroll(contentId) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
+
let url = `/challenges/enroll/${contentId}`
|
|
546
|
+
return await fetchHandler(url, 'post')
|
|
545
547
|
}
|
|
546
548
|
|
|
547
549
|
/**
|
|
@@ -552,8 +554,8 @@ export async function postChallengesEnroll(contentId) {
|
|
|
552
554
|
* @returns {Promise<any|null>}
|
|
553
555
|
*/
|
|
554
556
|
export async function postChallengesLeave(contentId) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
+
let url = `/challenges/leave/${contentId}`
|
|
558
|
+
return await fetchHandler(url, 'post')
|
|
557
559
|
}
|
|
558
560
|
|
|
559
561
|
/**
|
|
@@ -563,8 +565,8 @@ export async function postChallengesLeave(contentId) {
|
|
|
563
565
|
* @returns {Promise<any|null>}
|
|
564
566
|
*/
|
|
565
567
|
export async function postChallengesEnrollmentNotification(contentId) {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
+
let url = `/challenges/notifications/enrollment_open/${contentId}`
|
|
569
|
+
return await fetchHandler(url, 'post')
|
|
568
570
|
}
|
|
569
571
|
|
|
570
572
|
/**
|
|
@@ -574,8 +576,8 @@ export async function postChallengesEnrollmentNotification(contentId) {
|
|
|
574
576
|
* @returns {Promise<any|null>}
|
|
575
577
|
*/
|
|
576
578
|
export async function postChallengesCommunityNotification(contentId) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
+
let url = `/challenges/notifications/community_reminders/${contentId}`
|
|
580
|
+
return await fetchHandler(url, 'post')
|
|
579
581
|
}
|
|
580
582
|
|
|
581
583
|
/**
|
|
@@ -585,8 +587,8 @@ export async function postChallengesCommunityNotification(contentId) {
|
|
|
585
587
|
* @returns {Promise<any|null>}
|
|
586
588
|
*/
|
|
587
589
|
export async function postChallengesSoloNotification(contentId) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
+
let url = `/challenges/notifications/solo_reminders/${contentId}`
|
|
591
|
+
return await fetchHandler(url, 'post')
|
|
590
592
|
}
|
|
591
593
|
|
|
592
594
|
/**
|
|
@@ -596,9 +598,9 @@ export async function postChallengesSoloNotification(contentId) {
|
|
|
596
598
|
* @returns {Promise<any|null>} - Modal data to display
|
|
597
599
|
*/
|
|
598
600
|
export async function postChallengesCompleteLesson(contentId) {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
601
|
+
let url = `/challenges/complete_lesson/${contentId}`
|
|
602
|
+
await contentStatusCompleted(contentId)
|
|
603
|
+
return await fetchHandler(url, 'post')
|
|
602
604
|
}
|
|
603
605
|
|
|
604
606
|
/**
|
|
@@ -608,8 +610,8 @@ export async function postChallengesCompleteLesson(contentId) {
|
|
|
608
610
|
* @returns {Promise<any|null>}
|
|
609
611
|
*/
|
|
610
612
|
export async function postChallengesHideCompletedBanner(contentId) {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
+
let url = `/challenges/hide_completed_banner/${contentId}`
|
|
614
|
+
return await fetchHandler(url, 'post')
|
|
613
615
|
}
|
|
614
616
|
|
|
615
617
|
/**
|
|
@@ -631,18 +633,20 @@ export async function postChallengesHideCompletedBanner(contentId) {
|
|
|
631
633
|
* .then(playlists => console.log(playlists))
|
|
632
634
|
* .catch(error => console.error(error));
|
|
633
635
|
*/
|
|
634
|
-
export async function fetchUserPlaylists(
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
636
|
+
export async function fetchUserPlaylists(
|
|
637
|
+
brand,
|
|
638
|
+
{ page, limit, sort, searchTerm, content_id, categories } = {}
|
|
639
|
+
) {
|
|
640
|
+
let url
|
|
641
|
+
const limitString = limit ? `&limit=${limit}` : ''
|
|
642
|
+
const pageString = page ? `&page=${page}` : ''
|
|
643
|
+
const sortString = sort ? `&sort=${sort}` : ''
|
|
644
|
+
const searchFilter = searchTerm ? `&term=${searchTerm}` : ''
|
|
645
|
+
const content = content_id ? `&content_id=${content_id}` : ''
|
|
646
|
+
const categoryString =
|
|
647
|
+
categories && categories.length ? categories.map((cat) => `categories[]=${cat}`).join('&') : ''
|
|
648
|
+
url = `/playlists/all?brand=${brand}${limitString}${pageString}${sortString}${searchFilter}${content}${categoryString ? `&${categoryString}` : ''}`
|
|
649
|
+
return await fetchHandler(url)
|
|
646
650
|
}
|
|
647
651
|
|
|
648
652
|
/**
|
|
@@ -674,8 +678,8 @@ export async function fetchUserPlaylists(brand, {page, limit, sort, searchTerm,
|
|
|
674
678
|
* .catch(error => console.error('Error duplicating playlist:', error));
|
|
675
679
|
*/
|
|
676
680
|
export async function duplicatePlaylist(playlistId, playlistData) {
|
|
677
|
-
|
|
678
|
-
|
|
681
|
+
let url = `/playlists/duplicate/${playlistId}`
|
|
682
|
+
return await fetchHandler(url, 'post', null, playlistData)
|
|
679
683
|
}
|
|
680
684
|
|
|
681
685
|
/**
|
|
@@ -702,8 +706,8 @@ export async function duplicatePlaylist(playlistId, playlistData) {
|
|
|
702
706
|
* .catch(error => console.error('Error deleting playlist:', error));
|
|
703
707
|
*/
|
|
704
708
|
export async function deletePlaylist(playlistId) {
|
|
705
|
-
|
|
706
|
-
|
|
709
|
+
let url = `/playlists/playlist/${playlistId}`
|
|
710
|
+
return await fetchHandler(url, 'delete')
|
|
707
711
|
}
|
|
708
712
|
|
|
709
713
|
/**
|
|
@@ -737,8 +741,8 @@ export async function deletePlaylist(playlistId) {
|
|
|
737
741
|
* .catch(error => console.error('Error updating playlist:', error));
|
|
738
742
|
*/
|
|
739
743
|
export async function updatePlaylist(playlistId, updatedData) {
|
|
740
|
-
|
|
741
|
-
|
|
744
|
+
const url = `/playlists/playlist/${playlistId}`
|
|
745
|
+
return await fetchHandler(url, 'PUT', null, updatedData)
|
|
742
746
|
}
|
|
743
747
|
|
|
744
748
|
/**
|
|
@@ -767,8 +771,8 @@ export async function updatePlaylist(playlistId, updatedData) {
|
|
|
767
771
|
* .catch(error => console.error('Error creating playlist:', error));
|
|
768
772
|
*/
|
|
769
773
|
export async function createPlaylist(playlistData) {
|
|
770
|
-
|
|
771
|
-
|
|
774
|
+
const url = `/playlists/playlist`
|
|
775
|
+
return await fetchHandler(url, 'POST', null, playlistData)
|
|
772
776
|
}
|
|
773
777
|
|
|
774
778
|
/**
|
|
@@ -800,9 +804,9 @@ export async function createPlaylist(playlistData) {
|
|
|
800
804
|
* .catch(error => console.error('Error liking playlist:', error));
|
|
801
805
|
*/
|
|
802
806
|
export async function likePlaylist(playlistId) {
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
807
|
+
const url = `/playlists/like`
|
|
808
|
+
const payload = { playlist_id: playlistId }
|
|
809
|
+
return await fetchHandler(url, 'PUT', null, payload)
|
|
806
810
|
}
|
|
807
811
|
|
|
808
812
|
/**
|
|
@@ -827,9 +831,9 @@ export async function likePlaylist(playlistId) {
|
|
|
827
831
|
* .catch(error => console.error('Error removing playlist like:', error));
|
|
828
832
|
*/
|
|
829
833
|
export async function deletePlaylistLike(playlistId) {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
834
|
+
const url = `/playlists/like`
|
|
835
|
+
const payload = { playlist_id: playlistId }
|
|
836
|
+
return await fetchHandler(url, 'DELETE', null, payload)
|
|
833
837
|
}
|
|
834
838
|
|
|
835
839
|
/**
|
|
@@ -849,8 +853,8 @@ export async function deletePlaylistLike(playlistId) {
|
|
|
849
853
|
* .catch(error => console.error('Error fetching playlist:', error));
|
|
850
854
|
*/
|
|
851
855
|
export async function fetchPlaylist(playlistId) {
|
|
852
|
-
|
|
853
|
-
|
|
856
|
+
const url = `/playlists/playlist/${playlistId}`
|
|
857
|
+
return await fetchHandler(url, 'GET')
|
|
854
858
|
}
|
|
855
859
|
|
|
856
860
|
/**
|
|
@@ -868,10 +872,10 @@ export async function fetchPlaylist(playlistId) {
|
|
|
868
872
|
* .then(items => console.log(items))
|
|
869
873
|
* .catch(error => console.error('Error fetching playlist items:', error));
|
|
870
874
|
*/
|
|
871
|
-
export async function fetchPlaylistItems(playlistId, {sort} = {}) {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
+
export async function fetchPlaylistItems(playlistId, { sort } = {}) {
|
|
876
|
+
const sortString = sort ? `&sort=${sort}` : ''
|
|
877
|
+
const url = `/playlists/playlist-lessons?playlist_id=${playlistId}${sortString}`
|
|
878
|
+
return await fetchHandler(url, 'GET')
|
|
875
879
|
}
|
|
876
880
|
|
|
877
881
|
/**
|
|
@@ -910,8 +914,8 @@ export async function fetchPlaylistItems(playlistId, {sort} = {}) {
|
|
|
910
914
|
* });
|
|
911
915
|
*/
|
|
912
916
|
export async function updatePlaylistItem(updatedData) {
|
|
913
|
-
|
|
914
|
-
|
|
917
|
+
const url = `/playlists/item`
|
|
918
|
+
return await fetchHandler(url, 'POST', null, updatedData)
|
|
915
919
|
}
|
|
916
920
|
|
|
917
921
|
/**
|
|
@@ -945,8 +949,8 @@ export async function updatePlaylistItem(updatedData) {
|
|
|
945
949
|
* });
|
|
946
950
|
*/
|
|
947
951
|
export async function deletePlaylistItem(payload) {
|
|
948
|
-
|
|
949
|
-
|
|
952
|
+
const url = `/playlists/item`
|
|
953
|
+
return await fetchHandler(url, 'DELETE', null, payload)
|
|
950
954
|
}
|
|
951
955
|
|
|
952
956
|
/**
|
|
@@ -977,19 +981,19 @@ export async function deletePlaylistItem(payload) {
|
|
|
977
981
|
* });
|
|
978
982
|
*/
|
|
979
983
|
export async function fetchPlaylistItem(payload) {
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
984
|
+
const playlistItemId = payload.user_playlist_item_id
|
|
985
|
+
const url = `/playlists/item/${playlistItemId}`
|
|
986
|
+
return await fetchHandler(url)
|
|
983
987
|
}
|
|
984
988
|
|
|
985
989
|
export async function postContentCompleted(contentId) {
|
|
986
|
-
|
|
987
|
-
|
|
990
|
+
let url = `/content/user/progress/complete`
|
|
991
|
+
return postDataHandler(url, { contentId: contentId })
|
|
988
992
|
}
|
|
989
993
|
|
|
990
994
|
export async function postContentReset(contentId) {
|
|
991
|
-
|
|
992
|
-
|
|
995
|
+
let url = `/content/user/progress/reset`
|
|
996
|
+
return postDataHandler(url, { contentId: contentId })
|
|
993
997
|
}
|
|
994
998
|
|
|
995
999
|
/**
|
|
@@ -1033,8 +1037,8 @@ export async function postContentReset(contentId) {
|
|
|
1033
1037
|
* });
|
|
1034
1038
|
*/
|
|
1035
1039
|
export async function addItemToPlaylist(payload) {
|
|
1036
|
-
|
|
1037
|
-
|
|
1040
|
+
const url = `/playlists/add-item`
|
|
1041
|
+
return await fetchHandler(url, 'POST', null, payload)
|
|
1038
1042
|
}
|
|
1039
1043
|
|
|
1040
1044
|
/**
|
|
@@ -1063,8 +1067,8 @@ export async function addItemToPlaylist(payload) {
|
|
|
1063
1067
|
* });
|
|
1064
1068
|
*/
|
|
1065
1069
|
export async function countAssignmentsAndLessons(contentId) {
|
|
1066
|
-
|
|
1067
|
-
|
|
1070
|
+
const url = `/playlists/count-lessons-and-assignments/${contentId}`
|
|
1071
|
+
return await fetchHandler(url)
|
|
1068
1072
|
}
|
|
1069
1073
|
|
|
1070
1074
|
/**
|
|
@@ -1095,8 +1099,8 @@ export async function countAssignmentsAndLessons(contentId) {
|
|
|
1095
1099
|
* });
|
|
1096
1100
|
*/
|
|
1097
1101
|
export async function pinPlaylist(playlistId) {
|
|
1098
|
-
|
|
1099
|
-
|
|
1102
|
+
const url = `/playlists/pin/${playlistId}`
|
|
1103
|
+
return await fetchHandler(url, 'PUT')
|
|
1100
1104
|
}
|
|
1101
1105
|
|
|
1102
1106
|
/**
|
|
@@ -1127,8 +1131,8 @@ export async function pinPlaylist(playlistId) {
|
|
|
1127
1131
|
* });
|
|
1128
1132
|
*/
|
|
1129
1133
|
export async function unpinPlaylist(playlistId) {
|
|
1130
|
-
|
|
1131
|
-
|
|
1134
|
+
const url = `/playlists/unpin/${playlistId}`
|
|
1135
|
+
return await fetchHandler(url, 'PUT')
|
|
1132
1136
|
}
|
|
1133
1137
|
|
|
1134
1138
|
/**
|
|
@@ -1159,26 +1163,26 @@ export async function unpinPlaylist(playlistId) {
|
|
|
1159
1163
|
* });
|
|
1160
1164
|
*/
|
|
1161
1165
|
export async function fetchPinnedPlaylists(brand) {
|
|
1162
|
-
|
|
1163
|
-
|
|
1166
|
+
const url = `/playlists/my-pinned-playlists?brand=${brand}`
|
|
1167
|
+
return await fetchHandler(url, 'GET')
|
|
1164
1168
|
}
|
|
1165
1169
|
|
|
1166
1170
|
/**
|
|
1167
1171
|
* Report playlist endpoint
|
|
1168
|
-
*
|
|
1172
|
+
*
|
|
1169
1173
|
* @param playlistId
|
|
1170
1174
|
* @param issue
|
|
1171
1175
|
* @returns {Promise<any|null>}
|
|
1172
1176
|
*/
|
|
1173
|
-
export async function reportPlaylist(playlistId,
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
+
export async function reportPlaylist(playlistId, { issue } = {}) {
|
|
1178
|
+
const issueString = issue ? `?issue=${issue}` : ''
|
|
1179
|
+
const url = `/playlists/report/${playlistId}${issueString}`
|
|
1180
|
+
return await fetchHandler(url, 'PUT')
|
|
1177
1181
|
}
|
|
1178
1182
|
|
|
1179
1183
|
export async function playback(playlistId) {
|
|
1180
|
-
|
|
1181
|
-
|
|
1184
|
+
const url = `/playlists/play/${playlistId}`
|
|
1185
|
+
return await fetchHandler(url, 'GET')
|
|
1182
1186
|
}
|
|
1183
1187
|
|
|
1184
1188
|
/**
|
|
@@ -1189,20 +1193,20 @@ export async function playback(playlistId) {
|
|
|
1189
1193
|
* @returns {Promise<any|null>}
|
|
1190
1194
|
*/
|
|
1191
1195
|
export async function setStudentViewForUser(userId, enable) {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1196
|
+
let url = `/user-management-system/user/update/${userId}`
|
|
1197
|
+
let data = { use_student_view: enable ? 1 : 0 }
|
|
1198
|
+
return await patchDataHandler(url, data)
|
|
1195
1199
|
}
|
|
1196
1200
|
|
|
1197
1201
|
function fetchAbsolute(url, params) {
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1202
|
+
if (globalConfig.railcontentConfig.authToken) {
|
|
1203
|
+
params.headers['Authorization'] = `Bearer ${globalConfig.railcontentConfig.authToken}`
|
|
1204
|
+
}
|
|
1201
1205
|
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
}
|
|
1206
|
+
if (globalConfig.railcontentConfig.baseUrl) {
|
|
1207
|
+
if (url.startsWith('/')) {
|
|
1208
|
+
return fetch(globalConfig.railcontentConfig.baseUrl + url, params)
|
|
1206
1209
|
}
|
|
1207
|
-
|
|
1210
|
+
}
|
|
1211
|
+
return fetch(url, params)
|
|
1208
1212
|
}
|