musora-content-services 1.0.81 → 1.0.82
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/.github/workflows/node.js.yml +0 -0
- package/CHANGELOG.md +2 -0
- package/README.md +0 -0
- package/babel.config.js +0 -0
- package/docs/config.js.html +2 -2
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/index.html +2 -2
- package/docs/module-Config.html +2 -2
- package/docs/module-Railcontent-Services.html +344 -14
- package/docs/module-Sanity-Services.html +337 -24
- package/docs/railcontent.js.html +73 -9
- package/docs/sanity.js.html +52 -21
- package/docs/scripts/collapse.js +0 -0
- package/docs/scripts/commonNav.js +0 -0
- package/docs/scripts/linenumber.js +0 -0
- package/docs/scripts/nav.js +0 -0
- package/docs/scripts/polyfill.js +0 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +0 -0
- package/docs/scripts/prettify/lang-css.js +0 -0
- package/docs/scripts/prettify/prettify.js +0 -0
- package/docs/scripts/search.js +0 -0
- package/docs/styles/jsdoc.css +0 -0
- package/docs/styles/prettify.css +0 -0
- package/jest.config.js +0 -0
- package/jsdoc.json +0 -0
- package/package.json +1 -1
- package/src/services/config.js +0 -0
- package/src/services/sanity.js +15 -5
- package/test/sanityQueryService.test.js +12 -0
package/docs/railcontent.js.html
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Config.html">Config</a><ul class='methods'><li data-type='method'><a href="module-Config.html#~initializeService">initializeService</a></li></ul></li><li><a href="module-Railcontent-Services.html">Railcontent-Services</a><ul class='methods'><li data-type='method'><a href="module-Railcontent-Services.html#.fetchAllCompletedStates">fetchAllCompletedStates</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentInProgress">fetchContentInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Config.html">Config</a><ul class='methods'><li data-type='method'><a href="module-Config.html#~initializeService">initializeService</a></li></ul></li><li><a href="module-Railcontent-Services.html">Railcontent-Services</a><ul class='methods'><li data-type='method'><a href="module-Railcontent-Services.html#.fetchAllCompletedStates">fetchAllCompletedStates</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchCompletedState">fetchCompletedState</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentInProgress">fetchContentInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentPageUserData">fetchContentPageUserData</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchVimeoData">fetchVimeoData</a></li></ul></li><li><a href="module-Sanity-Services.html">Sanity-Services</a><ul class='methods'><li data-type='method'><a href="module-Sanity-Services.html#.fetchAll">fetchAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllFilterOptions">fetchAllFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllSongs">fetchAllSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchArtists">fetchArtists</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentId">fetchByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentIds">fetchByRailContentIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCatalogMetadata">fetchCatalogMetadata</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchChallengeOverview">fetchChallengeOverview</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchChildren">fetchChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCourseOverview">fetchCourseOverview</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchFoundation">fetchFoundation</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchLessonContent">fetchLessonContent</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethod">fetchMethod</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodChildren">fetchMethodChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodChildrenIds">fetchMethodChildrenIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodNextLesson">fetchMethodNextLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodPreviousNextLesson">fetchMethodPreviousNextLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethods">fetchMethods</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchNewReleases">fetchNewReleases</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchNextPreviousLesson">fetchNextPreviousLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchPackAll">fetchPackAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchPackChildren">fetchPackChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchParentByRailContentId">fetchParentByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchRelatedLessons">fetchRelatedLessons</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchRelatedSongs">fetchRelatedSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSanity">fetchSanity</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongArtistCount">fetchSongArtistCount</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongById">fetchSongById</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongCount">fetchSongCount</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongFilterOptions">fetchSongFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchUpcomingEvents">fetchUpcomingEvents</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchWorkouts">fetchWorkouts</a></li></ul></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -51,17 +51,18 @@
|
|
|
51
51
|
|
|
52
52
|
const { globalConfig } = require('./config');
|
|
53
53
|
|
|
54
|
+
|
|
54
55
|
/**
|
|
55
|
-
* Fetches the completion status of a specific
|
|
56
|
+
* Fetches the completion status of a specific lesson for the current user.
|
|
56
57
|
*
|
|
57
|
-
* @param {string} content_id - The ID of the
|
|
58
|
+
* @param {string} content_id - The ID of the lesson content to check.
|
|
58
59
|
* @returns {Promise<Object|null>} - Returns the completion status object if found, otherwise null.
|
|
59
60
|
* @example
|
|
60
|
-
* fetchCurrentSongComplete('user123', '
|
|
61
|
+
* fetchCurrentSongComplete('user123', 'lesson456', 'csrf-token')
|
|
61
62
|
* .then(status => console.log(status))
|
|
62
63
|
* .catch(error => console.error(error));
|
|
63
64
|
*/
|
|
64
|
-
export async function
|
|
65
|
+
export async function fetchCompletedState(content_id) {
|
|
65
66
|
const url = `/content/user_progress/${globalConfig.railcontentConfig.userId}?content_ids[]=${content_id}`;
|
|
66
67
|
|
|
67
68
|
const headers = {
|
|
@@ -73,9 +74,40 @@ export async function fetchCurrentSongComplete(content_id) {
|
|
|
73
74
|
const response = await fetch(url, { headers });
|
|
74
75
|
const result = await response.json();
|
|
75
76
|
|
|
76
|
-
if (result && result[content_id]) {
|
|
77
|
-
|
|
78
|
-
return
|
|
77
|
+
if (result && result[content_id]) { return result[content_id]; // Return the correct object
|
|
78
|
+
} else {
|
|
79
|
+
return null; // Handle unexpected structure
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error('Fetch error:', error);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Fetches the vimeo meta-data
|
|
89
|
+
*
|
|
90
|
+
* @param {string} vimeo_id - The vimeo id, found in the <document>.video.external_id field for lessons
|
|
91
|
+
* @returns {Promise<Object|null>} - Returns the
|
|
92
|
+
* @example
|
|
93
|
+
* fetchVimeoData('642900215')
|
|
94
|
+
* .then(vimeoData => console.log(vimeoData))
|
|
95
|
+
* .catch(error => console.error(error));
|
|
96
|
+
*/
|
|
97
|
+
export async function fetchVimeoData(vimeo_id) {
|
|
98
|
+
const url = `/content/vimeo-data/${vimeo_id}`;
|
|
99
|
+
|
|
100
|
+
const headers = {
|
|
101
|
+
'Content-Type': 'application/json',
|
|
102
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const response = await fetch(url, { headers });
|
|
107
|
+
const result = await response.json();
|
|
108
|
+
|
|
109
|
+
if (result) {
|
|
110
|
+
return result; // Return the correct object
|
|
79
111
|
} else {
|
|
80
112
|
console.log('Invalid result structure', result);
|
|
81
113
|
return null; // Handle unexpected structure
|
|
@@ -187,6 +219,38 @@ export async function fetchContentInProgress(type="all", brand) {
|
|
|
187
219
|
console.error('Fetch error:', error);
|
|
188
220
|
return null;
|
|
189
221
|
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Fetches user context data for a specific piece of content.
|
|
227
|
+
*
|
|
228
|
+
* @param {int} contentId - The content id.
|
|
229
|
+
* @returns {Promise<Object|null>} - Returns an object containing user context data if found, otherwise null.
|
|
230
|
+
* @example
|
|
231
|
+
* fetchContentPageUserData(406548)
|
|
232
|
+
* .then(data => console.log(data))
|
|
233
|
+
* .catch(error => console.error(error));
|
|
234
|
+
*/
|
|
235
|
+
export async function fetchContentPageUserData(contentId) {
|
|
236
|
+
let url = `/content/${contentId}/user_data/${globalConfig.railcontentConfig.userId}`;
|
|
237
|
+
const headers = {
|
|
238
|
+
'Content-Type': 'application/json',
|
|
239
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
240
|
+
};
|
|
241
|
+
try {
|
|
242
|
+
const response = await fetch(url, { headers });
|
|
243
|
+
const result = await response.json();
|
|
244
|
+
if(result){
|
|
245
|
+
console.log('fetchContentPageUserData', result);
|
|
246
|
+
return result;
|
|
247
|
+
} else {
|
|
248
|
+
console.log('result not json');
|
|
249
|
+
}
|
|
250
|
+
} catch (error) {
|
|
251
|
+
console.error('Fetch error:', error);
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
190
254
|
}</code></pre>
|
|
191
255
|
</article>
|
|
192
256
|
</section>
|
|
@@ -201,7 +265,7 @@ export async function fetchContentInProgress(type="all", brand) {
|
|
|
201
265
|
<br class="clear">
|
|
202
266
|
|
|
203
267
|
<footer>
|
|
204
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on
|
|
268
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Fri Sep 06 2024 17:01:42 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
205
269
|
</footer>
|
|
206
270
|
|
|
207
271
|
<script>prettyPrint();</script>
|
package/docs/sanity.js.html
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Config.html">Config</a><ul class='methods'><li data-type='method'><a href="module-Config.html#~initializeService">initializeService</a></li></ul></li><li><a href="module-Railcontent-Services.html">Railcontent-Services</a><ul class='methods'><li data-type='method'><a href="module-Railcontent-Services.html#.fetchAllCompletedStates">fetchAllCompletedStates</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentInProgress">fetchContentInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Config.html">Config</a><ul class='methods'><li data-type='method'><a href="module-Config.html#~initializeService">initializeService</a></li></ul></li><li><a href="module-Railcontent-Services.html">Railcontent-Services</a><ul class='methods'><li data-type='method'><a href="module-Railcontent-Services.html#.fetchAllCompletedStates">fetchAllCompletedStates</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchCompletedState">fetchCompletedState</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentInProgress">fetchContentInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentPageUserData">fetchContentPageUserData</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchVimeoData">fetchVimeoData</a></li></ul></li><li><a href="module-Sanity-Services.html">Sanity-Services</a><ul class='methods'><li data-type='method'><a href="module-Sanity-Services.html#.fetchAll">fetchAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllFilterOptions">fetchAllFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllSongs">fetchAllSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchArtists">fetchArtists</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentId">fetchByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentIds">fetchByRailContentIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCatalogMetadata">fetchCatalogMetadata</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchChallengeOverview">fetchChallengeOverview</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchChildren">fetchChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCourseOverview">fetchCourseOverview</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchFoundation">fetchFoundation</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchLessonContent">fetchLessonContent</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethod">fetchMethod</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodChildren">fetchMethodChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodChildrenIds">fetchMethodChildrenIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodNextLesson">fetchMethodNextLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodPreviousNextLesson">fetchMethodPreviousNextLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethods">fetchMethods</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchNewReleases">fetchNewReleases</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchNextPreviousLesson">fetchNextPreviousLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchPackAll">fetchPackAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchPackChildren">fetchPackChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchParentByRailContentId">fetchParentByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchRelatedLessons">fetchRelatedLessons</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchRelatedSongs">fetchRelatedSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSanity">fetchSanity</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongArtistCount">fetchSongArtistCount</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongById">fetchSongById</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongCount">fetchSongCount</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongFilterOptions">fetchSongFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchUpcomingEvents">fetchUpcomingEvents</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchWorkouts">fetchWorkouts</a></li></ul></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -376,7 +376,6 @@ export async function fetchUpcomingEvents(brand) {
|
|
|
376
376
|
* .catch(error => console.error(error));
|
|
377
377
|
*/
|
|
378
378
|
export async function fetchByRailContentId(id, contentType) {
|
|
379
|
-
console.log('contentType', contentType)
|
|
380
379
|
const query = `*[railcontent_id == ${id}]{
|
|
381
380
|
${getFieldsForContentType(contentType)}
|
|
382
381
|
}`
|
|
@@ -414,6 +413,9 @@ export async function fetchByRailContentIds(ids, contentType = undefined) {
|
|
|
414
413
|
* @param {string} [params.sort="-published_on"] - The field to sort the content by.
|
|
415
414
|
* @param {Array<string>} [params.includedFields=[]] - The fields to include in the query.
|
|
416
415
|
* @param {string} [params.groupBy=""] - The field to group the results by (e.g., 'artist', 'genre').
|
|
416
|
+
* @param {Array<string>} [params.progressIds=undefined] - An array of railcontent IDs to filter the results by. Used for filtering by progress.
|
|
417
|
+
* @param {boolean} [params.useDefaultFields=true] - use the default sanity fields for content Type
|
|
418
|
+
* @param {Array<string>} [params.customFields=[]] - An array of sanity fields to include in the request
|
|
417
419
|
* @returns {Promise<Object|null>} - The fetched content data or null if not found.
|
|
418
420
|
*
|
|
419
421
|
* @example
|
|
@@ -423,7 +425,10 @@ export async function fetchByRailContentIds(ids, contentType = undefined) {
|
|
|
423
425
|
* searchTerm: 'jazz',
|
|
424
426
|
* sort: '-popularity',
|
|
425
427
|
* includedFields: ['difficulty,Intermediate'],
|
|
426
|
-
* groupBy: 'artist'
|
|
428
|
+
* groupBy: 'artist',
|
|
429
|
+
* progressIds: [123, 321],
|
|
430
|
+
* useDefaultFields: false,
|
|
431
|
+
* customFields: ['is_house_coach', 'slug.current', "'instructors': instructor[]->name"],
|
|
427
432
|
* })
|
|
428
433
|
* .then(content => console.log(content))
|
|
429
434
|
* .catch(error => console.error(error));
|
|
@@ -434,7 +439,10 @@ export async function fetchAll(brand, type, {
|
|
|
434
439
|
searchTerm = "",
|
|
435
440
|
sort = "-published_on",
|
|
436
441
|
includedFields = [],
|
|
437
|
-
groupBy = ""
|
|
442
|
+
groupBy = "",
|
|
443
|
+
progressIds = undefined,
|
|
444
|
+
useDefaultFields = true,
|
|
445
|
+
customFields = [],
|
|
438
446
|
} = {}) {
|
|
439
447
|
let config = contentTypeConfig[type] ?? {};
|
|
440
448
|
let additionalFields = config?.fields ?? [];
|
|
@@ -454,10 +462,14 @@ export async function fetchAll(brand, type, {
|
|
|
454
462
|
? filtersToGroq(includedFields)
|
|
455
463
|
: "";
|
|
456
464
|
|
|
465
|
+
// limits the results to supplied progressIds for started & completed filters
|
|
466
|
+
const progressFilter = progressIds !== undefined ?
|
|
467
|
+
`&& railcontent_id in [${progressIds.join(',')}]` : "";
|
|
468
|
+
|
|
457
469
|
// Determine the sort order
|
|
458
470
|
const sortOrder = getSortOrder(sort);
|
|
459
471
|
|
|
460
|
-
let fields =
|
|
472
|
+
let fields = useDefaultFields ? customFields.concat(DEFAULT_FIELDS, additionalFields) : customFields;
|
|
461
473
|
let fieldsString = fields.join(',');
|
|
462
474
|
|
|
463
475
|
// Determine the group by clause
|
|
@@ -465,15 +477,15 @@ export async function fetchAll(brand, type, {
|
|
|
465
477
|
if (groupBy !== "" && isGroupByOneToOne) {
|
|
466
478
|
query = `
|
|
467
479
|
{
|
|
468
|
-
"total": count(*[_type == '${groupBy}' && count(*[_type == '${type}' && brand == '${brand}' && ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter}]._id) > 0]),
|
|
469
|
-
"entity": *[_type == '${groupBy}' && count(*[_type == '${type}' && brand == '${brand}' && ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter}]._id) > 0]
|
|
480
|
+
"total": count(*[_type == '${groupBy}' && count(*[_type == '${type}' && brand == '${brand}' && ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]),
|
|
481
|
+
"entity": *[_type == '${groupBy}' && count(*[_type == '${type}' && brand == '${brand}' && ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]
|
|
470
482
|
{
|
|
471
483
|
'id': _id,
|
|
472
484
|
'type': _type,
|
|
473
485
|
name,
|
|
474
486
|
'head_shot_picture_url': thumbnail_url.asset->url,
|
|
475
|
-
'all_lessons_count': count(*[_type == '${type}' && brand == '${brand}' && ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter}]._id),
|
|
476
|
-
'lessons': *[_type == '${type}' && brand == '${brand}' && ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter}]{
|
|
487
|
+
'all_lessons_count': count(*[_type == '${type}' && brand == '${brand}' && ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id),
|
|
488
|
+
'lessons': *[_type == '${type}' && brand == '${brand}' && ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]{
|
|
477
489
|
${fieldsString},
|
|
478
490
|
${groupBy}
|
|
479
491
|
}[0...10]
|
|
@@ -484,15 +496,15 @@ export async function fetchAll(brand, type, {
|
|
|
484
496
|
} else if (groupBy !== "") {
|
|
485
497
|
query = `
|
|
486
498
|
{
|
|
487
|
-
"total": count(*[_type == '${groupBy}' && count(*[_type == '${type}' && brand == '${brand}' && ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter}]._id) > 0]),
|
|
488
|
-
"entity": *[_type == '${groupBy}' && count(*[_type == '${type}' && brand == '${brand}' && ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter}]._id) > 0]
|
|
499
|
+
"total": count(*[_type == '${groupBy}' && count(*[_type == '${type}' && brand == '${brand}' && ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]),
|
|
500
|
+
"entity": *[_type == '${groupBy}' && count(*[_type == '${type}' && brand == '${brand}' && ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]
|
|
489
501
|
{
|
|
490
502
|
'id': _id,
|
|
491
503
|
'type': _type,
|
|
492
504
|
name,
|
|
493
505
|
'head_shot_picture_url': thumbnail_url.asset->url,
|
|
494
|
-
'all_lessons_count': count(*[_type == '${type}' && brand == '${brand}' && ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter}]._id),
|
|
495
|
-
'lessons': *[_type == '${type}' && brand == '${brand}' && ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter}]{
|
|
506
|
+
'all_lessons_count': count(*[_type == '${type}' && brand == '${brand}' && ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id),
|
|
507
|
+
'lessons': *[_type == '${type}' && brand == '${brand}' && ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]{
|
|
496
508
|
${fieldsString},
|
|
497
509
|
${groupBy}
|
|
498
510
|
}[0...10]
|
|
@@ -503,10 +515,10 @@ export async function fetchAll(brand, type, {
|
|
|
503
515
|
} else {
|
|
504
516
|
query = `
|
|
505
517
|
{
|
|
506
|
-
"entity": *[_type == '${type}' && brand == "${brand}" ${searchFilter} ${includedFieldsFilter}] | order(${sortOrder}) [${start}...${end}] {
|
|
507
|
-
${fieldsString}
|
|
518
|
+
"entity": *[_type == '${type}' && brand == "${brand}" ${searchFilter} ${includedFieldsFilter} ${progressFilter}] | order(${sortOrder}) [${start}...${end}] {
|
|
519
|
+
${fieldsString},
|
|
508
520
|
},
|
|
509
|
-
"total": count(*[_type == '${type}' && brand == "${brand}" ${searchFilter} ${includedFieldsFilter}])
|
|
521
|
+
"total": count(*[_type == '${type}' && brand == "${brand}" ${searchFilter} ${includedFieldsFilter} ${progressFilter}])
|
|
510
522
|
}
|
|
511
523
|
`;
|
|
512
524
|
}
|
|
@@ -548,7 +560,7 @@ export function getSortOrder(sort= '-published_on', groupBy)
|
|
|
548
560
|
* @param {string} [artist] - Optional artist name to filter the results. If provided, the query will check if the artist's name matches.
|
|
549
561
|
* @param {string} contentType - The content type to fetch (e.g., 'song', 'lesson').
|
|
550
562
|
* @param {string} [term] - Optional search term to match against various fields such as title, album, artist name, and genre.
|
|
551
|
-
*
|
|
563
|
+
* @param {Array<string>} [progressIds=undefined] - An array of railcontent IDs to filter the results by. Used for filtering by progress.
|
|
552
564
|
* @returns {Promise<Object|null>} - A promise that resolves to an object containing the total results and filter options, or null if the query fails.
|
|
553
565
|
*
|
|
554
566
|
* @example
|
|
@@ -563,11 +575,15 @@ export async function fetchAllFilterOptions(
|
|
|
563
575
|
style,
|
|
564
576
|
artist,
|
|
565
577
|
contentType,
|
|
566
|
-
term
|
|
578
|
+
term,
|
|
579
|
+
progressIds = undefined
|
|
567
580
|
) {
|
|
568
581
|
const includedFieldsFilter = filters?.length > 0 ? filtersToGroq(filters) : undefined;
|
|
569
582
|
|
|
570
|
-
const
|
|
583
|
+
const progressFilter = progressIds !== undefined ?
|
|
584
|
+
`&& railcontent_id in [${progressIds.join(',')}]` : "";
|
|
585
|
+
|
|
586
|
+
const commonFilter = `_type == '${contentType}' && brand == "${brand}"${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} ${progressFilter} ${includedFieldsFilter ? includedFieldsFilter : ''}`;
|
|
571
587
|
const query = `
|
|
572
588
|
{
|
|
573
589
|
"meta": {
|
|
@@ -642,6 +658,18 @@ export async function fetchMethods(brand) {
|
|
|
642
658
|
return fetchSanity(query, true);
|
|
643
659
|
}
|
|
644
660
|
|
|
661
|
+
/**
|
|
662
|
+
* Fetch the Foundations 2019.
|
|
663
|
+
* @param {string} slug - The slug of the method.
|
|
664
|
+
* @returns {Promise<Object|null>} - The fetched foundation data or null if not found.
|
|
665
|
+
*/
|
|
666
|
+
export async function fetchFoundation(slug) {
|
|
667
|
+
const query = `*[_type == 'foundation' && slug.current == "${slug}"] {
|
|
668
|
+
${ getFieldsForContentType('foundation') }
|
|
669
|
+
} | order(published_on asc)`
|
|
670
|
+
return fetchSanity(query, false);
|
|
671
|
+
}
|
|
672
|
+
|
|
645
673
|
/**
|
|
646
674
|
* Fetch the Method (learning-paths) for a specific brand.
|
|
647
675
|
* @param {string} brand - The brand for which to fetch methods.
|
|
@@ -916,7 +944,10 @@ export async function fetchLiveEvent(brand) {
|
|
|
916
944
|
'event_coach_calendar_id': coalesce(calendar_id, '${defaultCalendarID}'),
|
|
917
945
|
title,
|
|
918
946
|
"image": thumbnail.asset->url,
|
|
919
|
-
"instructors": instructor[]->
|
|
947
|
+
"instructors": instructor[]->{
|
|
948
|
+
name,
|
|
949
|
+
web_url_path,
|
|
950
|
+
},
|
|
920
951
|
'videoId': coalesce(live_event_youtube_id, video.external_id),
|
|
921
952
|
} | order(live_event_start_time)[0...1]`;
|
|
922
953
|
return await fetchSanity(query, false);
|
|
@@ -1125,7 +1156,7 @@ function checkSanityConfig(config) {
|
|
|
1125
1156
|
<br class="clear">
|
|
1126
1157
|
|
|
1127
1158
|
<footer>
|
|
1128
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on
|
|
1159
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Fri Sep 06 2024 17:01:42 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1129
1160
|
</footer>
|
|
1130
1161
|
|
|
1131
1162
|
<script>prettyPrint();</script>
|
package/docs/scripts/collapse.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/scripts/nav.js
CHANGED
|
File without changes
|
package/docs/scripts/polyfill.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/scripts/search.js
CHANGED
|
File without changes
|
package/docs/styles/jsdoc.css
CHANGED
|
File without changes
|
package/docs/styles/prettify.css
CHANGED
|
File without changes
|
package/jest.config.js
CHANGED
|
File without changes
|
package/jsdoc.json
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/src/services/config.js
CHANGED
|
File without changes
|
package/src/services/sanity.js
CHANGED
|
@@ -367,6 +367,8 @@ export async function fetchByRailContentIds(ids, contentType = undefined) {
|
|
|
367
367
|
* @param {Array<string>} [params.includedFields=[]] - The fields to include in the query.
|
|
368
368
|
* @param {string} [params.groupBy=""] - The field to group the results by (e.g., 'artist', 'genre').
|
|
369
369
|
* @param {Array<string>} [params.progressIds=undefined] - An array of railcontent IDs to filter the results by. Used for filtering by progress.
|
|
370
|
+
* @param {boolean} [params.useDefaultFields=true] - use the default sanity fields for content Type
|
|
371
|
+
* @param {Array<string>} [params.customFields=[]] - An array of sanity fields to include in the request
|
|
370
372
|
* @returns {Promise<Object|null>} - The fetched content data or null if not found.
|
|
371
373
|
*
|
|
372
374
|
* @example
|
|
@@ -376,7 +378,10 @@ export async function fetchByRailContentIds(ids, contentType = undefined) {
|
|
|
376
378
|
* searchTerm: 'jazz',
|
|
377
379
|
* sort: '-popularity',
|
|
378
380
|
* includedFields: ['difficulty,Intermediate'],
|
|
379
|
-
* groupBy: 'artist'
|
|
381
|
+
* groupBy: 'artist',
|
|
382
|
+
* progressIds: [123, 321],
|
|
383
|
+
* useDefaultFields: false,
|
|
384
|
+
* customFields: ['is_house_coach', 'slug.current', "'instructors': instructor[]->name"],
|
|
380
385
|
* })
|
|
381
386
|
* .then(content => console.log(content))
|
|
382
387
|
* .catch(error => console.error(error));
|
|
@@ -388,7 +393,9 @@ export async function fetchAll(brand, type, {
|
|
|
388
393
|
sort = "-published_on",
|
|
389
394
|
includedFields = [],
|
|
390
395
|
groupBy = "",
|
|
391
|
-
progressIds = undefined
|
|
396
|
+
progressIds = undefined,
|
|
397
|
+
useDefaultFields = true,
|
|
398
|
+
customFields = [],
|
|
392
399
|
} = {}) {
|
|
393
400
|
let config = contentTypeConfig[type] ?? {};
|
|
394
401
|
let additionalFields = config?.fields ?? [];
|
|
@@ -415,7 +422,7 @@ export async function fetchAll(brand, type, {
|
|
|
415
422
|
// Determine the sort order
|
|
416
423
|
const sortOrder = getSortOrder(sort);
|
|
417
424
|
|
|
418
|
-
let fields =
|
|
425
|
+
let fields = useDefaultFields ? customFields.concat(DEFAULT_FIELDS, additionalFields) : customFields;
|
|
419
426
|
let fieldsString = fields.join(',');
|
|
420
427
|
|
|
421
428
|
// Determine the group by clause
|
|
@@ -462,7 +469,7 @@ export async function fetchAll(brand, type, {
|
|
|
462
469
|
query = `
|
|
463
470
|
{
|
|
464
471
|
"entity": *[_type == '${type}' && brand == "${brand}" ${searchFilter} ${includedFieldsFilter} ${progressFilter}] | order(${sortOrder}) [${start}...${end}] {
|
|
465
|
-
${fieldsString}
|
|
472
|
+
${fieldsString},
|
|
466
473
|
},
|
|
467
474
|
"total": count(*[_type == '${type}' && brand == "${brand}" ${searchFilter} ${includedFieldsFilter} ${progressFilter}])
|
|
468
475
|
}
|
|
@@ -890,7 +897,10 @@ export async function fetchLiveEvent(brand) {
|
|
|
890
897
|
'event_coach_calendar_id': coalesce(calendar_id, '${defaultCalendarID}'),
|
|
891
898
|
title,
|
|
892
899
|
"image": thumbnail.asset->url,
|
|
893
|
-
"instructors": instructor[]->
|
|
900
|
+
"instructors": instructor[]->{
|
|
901
|
+
name,
|
|
902
|
+
web_url_path,
|
|
903
|
+
},
|
|
894
904
|
'videoId': coalesce(live_event_youtube_id, video.external_id),
|
|
895
905
|
} | order(live_event_start_time)[0...1]`;
|
|
896
906
|
return await fetchSanity(query, false);
|
|
@@ -139,6 +139,18 @@ describe('Sanity Queries', function () {
|
|
|
139
139
|
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
+
test('fetchAll-CustomFields', async () => {
|
|
143
|
+
let response = await fetchAll('drumeo', 'challenge',{customFields:['garbage']});
|
|
144
|
+
console.log(response);
|
|
145
|
+
expect(response.entity[0].garbage).toBeDefined();
|
|
146
|
+
expect(response.entity[0].id).toBeDefined();
|
|
147
|
+
|
|
148
|
+
response = await fetchAll('drumeo', 'challenge',{useDefaultFields: false, customFields:['garbage']});
|
|
149
|
+
console.log(response);
|
|
150
|
+
expect(response.entity[0].garbage).toBeDefined();
|
|
151
|
+
expect.not.objectContaining(response.entity[0].id);
|
|
152
|
+
});
|
|
153
|
+
|
|
142
154
|
test('fetchRelatedLessons', async () => {
|
|
143
155
|
const id = 380094;
|
|
144
156
|
const document = await fetchByRailContentId(id);
|