musora-content-services 1.0.81 → 1.0.83

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.
@@ -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#.fetchCurrentSongComplete">fetchCurrentSongComplete</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</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#.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>
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 song for the current user.
56
+ * Fetches the completion status of a specific lesson for the current user.
56
57
  *
57
- * @param {string} content_id - The ID of the song content to check.
58
+ * @param {string} content_id - The ID of the lesson content to check.
58
59
  * @returns {Promise&lt;Object|null>} - Returns the completion status object if found, otherwise null.
59
60
  * @example
60
- * fetchCurrentSongComplete('user123', 'song456', 'csrf-token')
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 fetchCurrentSongComplete(content_id) {
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 &amp;&amp; result[content_id]) {
77
- console.log('result', result[content_id]);
78
- return result[content_id]; // Return the correct object
77
+ if (result &amp;&amp; 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 &lt;document>.video.external_id field for lessons
91
+ * @returns {Promise&lt;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&lt;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 Tue Sep 03 2024 21:48:28 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
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>
@@ -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#.fetchCurrentSongComplete">fetchCurrentSongComplete</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</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#.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>
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&lt;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&lt;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&lt;string>} [params.customFields=[]] - An array of sanity fields to include in the request
417
419
  * @returns {Promise&lt;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 &amp; completed filters
466
+ const progressFilter = progressIds !== undefined ?
467
+ `&amp;&amp; railcontent_id in [${progressIds.join(',')}]` : "";
468
+
457
469
  // Determine the sort order
458
470
  const sortOrder = getSortOrder(sort);
459
471
 
460
- let fields = DEFAULT_FIELDS.concat(additionalFields);
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 !== "" &amp;&amp; isGroupByOneToOne) {
466
478
  query = `
467
479
  {
468
- "total": count(*[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter}]._id) > 0]),
469
- "entity": *[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter}]._id) > 0]
480
+ "total": count(*[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]),
481
+ "entity": *[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._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}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter}]._id),
476
- 'lessons': *[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter}]{
487
+ 'all_lessons_count': count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id),
488
+ 'lessons': *[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._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}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter}]._id) > 0]),
488
- "entity": *[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter}]._id) > 0]
499
+ "total": count(*[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]),
500
+ "entity": *[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._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}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter}]._id),
495
- 'lessons': *[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter}]{
506
+ 'all_lessons_count': count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id),
507
+ 'lessons': *[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._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}' &amp;&amp; brand == "${brand}" ${searchFilter} ${includedFieldsFilter}] | order(${sortOrder}) [${start}...${end}] {
507
- ${fieldsString}
518
+ "entity": *[_type == '${type}' &amp;&amp; brand == "${brand}" ${searchFilter} ${includedFieldsFilter} ${progressFilter}] | order(${sortOrder}) [${start}...${end}] {
519
+ ${fieldsString},
508
520
  },
509
- "total": count(*[_type == '${type}' &amp;&amp; brand == "${brand}" ${searchFilter} ${includedFieldsFilter}])
521
+ "total": count(*[_type == '${type}' &amp;&amp; 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&lt;string>} [progressIds=undefined] - An array of railcontent IDs to filter the results by. Used for filtering by progress.
552
564
  * @returns {Promise&lt;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 commonFilter = `_type == '${contentType}' &amp;&amp; brand == "${brand}"${style ? ` &amp;&amp; '${style}' in genre[]->name` : ''}${artist ? ` &amp;&amp; artist->name == '${artist}'` : ''} ${includedFieldsFilter ? includedFieldsFilter : ''}`;
583
+ const progressFilter = progressIds !== undefined ?
584
+ `&amp;&amp; railcontent_id in [${progressIds.join(',')}]` : "";
585
+
586
+ const commonFilter = `_type == '${contentType}' &amp;&amp; brand == "${brand}"${style ? ` &amp;&amp; '${style}' in genre[]->name` : ''}${artist ? ` &amp;&amp; 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&lt;Object|null>} - The fetched foundation data or null if not found.
665
+ */
666
+ export async function fetchFoundation(slug) {
667
+ const query = `*[_type == 'foundation' &amp;&amp; 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[]->name,
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 Tue Sep 03 2024 21:48:28 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.81",
3
+ "version": "1.0.83",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -225,17 +225,19 @@ function getFieldsForContentType(contentType, asQueryString=true) {
225
225
  function filtersToGroq(filters) {
226
226
  const groq = filters.map(field => {
227
227
  let [key, value] = field.split(',');
228
- switch (key) {
229
- case 'difficulty':
230
- return `&& difficulty_string == "${value}"`;
231
- case 'genre':
232
- return `&& genre[]->name match "${value}"`;
233
- case 'topic':
234
- return `&& topic[]->name match "${value}"`;
235
- case 'instrumentless':
236
- return `&& instrumentless == ${value}`;
237
- default:
238
- return `&& ${key} == ${/^\d+$/.test(value) ? value : `"$${value}"`}`;
228
+ if(key && value){
229
+ switch (key) {
230
+ case 'difficulty':
231
+ return `&& difficulty_string == "${value}"`;
232
+ case 'genre':
233
+ return `&& genre[]->name match "${value}"`;
234
+ case 'topic':
235
+ return `&& topic[]->name match "${value}"`;
236
+ case 'instrumentless':
237
+ return `&& instrumentless == ${value}`;
238
+ default:
239
+ return `&& ${key} == ${/^\d+$/.test(value) ? value : `"$${value}"`}`;
240
+ }
239
241
  }
240
242
  }).join(' ');
241
243
  return groq;
package/src/index.js CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  fetchMethodPreviousNextLesson,
33
33
  fetchLiveEvent,
34
34
  fetchChallengeOverview,
35
+ fetchCoachLessons,
35
36
  } from './services/sanity.js';
36
37
 
37
38
  import {
@@ -81,4 +82,5 @@ export {
81
82
  fetchChallengeOverview,
82
83
  fetchVimeoData,
83
84
  fetchContentPageUserData,
85
+ fetchCoachLessons,
84
86
  }
@@ -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 = DEFAULT_FIELDS.concat(additionalFields);
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[]->name,
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);
@@ -938,6 +948,37 @@ export async function fetchChallengeOverview(id) {
938
948
  return fetchSanity(query, false);
939
949
  }
940
950
 
951
+ /**
952
+ * Fetch the data needed for the coach screen.
953
+ * @param {string} id - The Railcontent ID of the coach
954
+ * @returns {Promise<Object|null>} - The lessons for the instructor or null if not found.
955
+ *
956
+ * @example
957
+ * fetchCoachLessons('coach123')
958
+ * .then(lessons => console.log(lessons))
959
+ * .catch(error => console.error(error));
960
+ */
961
+ export async function fetchCoachLessons(brand, id, {
962
+ sortOrder = '-published_on',
963
+ searchTerm = '',
964
+ page = 1,
965
+ limit = 20,
966
+ } = {}) {
967
+ const fieldsString = DEFAULT_FIELDS.join(',');
968
+ const start = (page - 1) * limit;
969
+ const end = start + limit;
970
+ const searchFilter = searchTerm ? `&& title match "${searchTerm}*"`: ''
971
+
972
+ const query = `{
973
+ "entity": *[brand == '${brand}' ${searchFilter} && references(*[_type=='instructor' && railcontent_id == ${id}]._id)] | order(${sortOrder}) [${start}...${end}]
974
+ {
975
+ ${fieldsString}
976
+ },
977
+ "total": count(*[brand == '${brand}' && references(*[_type=='instructor' && railcontent_id == ${id}]._id)])
978
+ }`;
979
+ return fetchSanity(query, true);
980
+ }
981
+
941
982
  /**
942
983
  * Fetch the data needed for the Course Overview screen.
943
984
  * @param {string} id - The Railcontent ID of the course
@@ -28,6 +28,7 @@ const {
28
28
  fetchMethod,
29
29
  fetchMethods,
30
30
  fetchFoundation,
31
+ fetchCoachLessons,
31
32
  } = require('../src/services/sanity.js');
32
33
 
33
34
  describe('Sanity Queries', function () {
@@ -139,6 +140,18 @@ describe('Sanity Queries', function () {
139
140
 
140
141
  });
141
142
 
143
+ test('fetchAll-CustomFields', async () => {
144
+ let response = await fetchAll('drumeo', 'challenge',{customFields:['garbage']});
145
+ console.log(response);
146
+ expect(response.entity[0].garbage).toBeDefined();
147
+ expect(response.entity[0].id).toBeDefined();
148
+
149
+ response = await fetchAll('drumeo', 'challenge',{useDefaultFields: false, customFields:['garbage']});
150
+ console.log(response);
151
+ expect(response.entity[0].garbage).toBeDefined();
152
+ expect.not.objectContaining(response.entity[0].id);
153
+ });
154
+
142
155
  test('fetchRelatedLessons', async () => {
143
156
  const id = 380094;
144
157
  const document = await fetchByRailContentId(id);
@@ -200,7 +213,7 @@ describe('Sanity Queries', function () {
200
213
 
201
214
  test('fetchMethods', async () => {
202
215
  const response = await fetchMethods('drumeo');
203
- //console.log(response);
216
+ console.log(response);
204
217
  expect(response.length).toBeGreaterThan(0);
205
218
  expect(response[0].type).toBe('learning-path');
206
219
  });
@@ -234,8 +247,13 @@ describe('Sanity Queries', function () {
234
247
 
235
248
  test('fetchFoundation', async () => {
236
249
  const response = await fetchFoundation('foundations-2019');
237
- //console.log(response);
250
+ console.log(response);
238
251
  expect(response.units.length).toBeGreaterThan(0);
239
252
  expect(response.type).toBe('foundation');
240
253
  });
254
+
255
+ test('fetchCoachLessons', async () => {
256
+ const response = await fetchCoachLessons('drumeo',233797);
257
+ expect(response.entity.length).toBeGreaterThan(0);
258
+ });
241
259
  });