musora-content-services 1.0.89 → 1.0.91

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#.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#.fetchAllPacks">fetchAllPacks</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#.fetchCoachLessons">fetchCoachLessons</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>
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#.fetchCompletedContent">fetchCompletedContent</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#.fetchAllPacks">fetchAllPacks</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#.fetchByReference">fetchByReference</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#.fetchCoachLessons">fetchCoachLessons</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
 
@@ -271,7 +271,7 @@ export async function fetchSongFilterOptions(brand) {
271
271
  */
272
272
  export async function fetchSongCount(brand) {
273
273
  const query = `count(*[_type == 'song' &amp;&amp; brand == "${brand}"])`;
274
- return fetchSanity(query, false);
274
+ return fetchSanity(query, true);
275
275
  }
276
276
 
277
277
  /**
@@ -719,6 +719,7 @@ export async function fetchMethodChildren(railcontentId) {
719
719
  "description": ${descriptionField},
720
720
  title,
721
721
  xp,
722
+ total_xp,
722
723
  'children': child[]->{
723
724
  ${getFieldsForContentType('method')}
724
725
  },
@@ -859,7 +860,9 @@ export async function fetchLessonContent(railContentId) {
859
860
  "instructors":instructor[]->name,
860
861
  instructor[]->,
861
862
  ${assignmentsField}
862
- video}`
863
+ video,
864
+ length_in_seconds
865
+ }`
863
866
  return fetchSanity(query, false);
864
867
  }
865
868
 
@@ -867,17 +870,20 @@ export async function fetchLessonContent(railContentId) {
867
870
  * Fetch related lessons for a specific lesson by RailContent ID and type.
868
871
  * @param {string} railContentId - The RailContent ID of the current lesson.
869
872
  * @param {string} brand - The current brand.
870
- * @param {string} contentType - name of the contentype to pull
871
873
  * @returns {Promise&lt;Array&lt;Object>|null>} - The fetched related lessons data or null if not found.
872
874
  */
873
- export async function fetchRelatedLessons(railContentId, brand, contentType) {
874
- let typeQuery = contentType ? `_type=="${contentType}" &amp;&amp;` : "";
875
-
875
+ export async function fetchRelatedLessons(railContentId, brand) {
876
+ // let sort = 'published_on'
877
+ // if (type == 'rhythmic-adventures-of-captain-carson' ||
878
+ // type == 'diy-drum-experiments' ||
879
+ // type == 'in-rhythm') {
880
+ // sort = 'sort';
881
+ // }
876
882
  //TODO: Implement $this->contentService->getFiltered
877
883
  const query = `*[railcontent_id == ${railContentId} &amp;&amp; brand == "${brand}" &amp;&amp; references(*[_type=='permission']._id)]{
878
884
  "related_lessons" : array::unique([
879
- _...(*[${typeQuery} brand == "${brand}" &amp;&amp; references(^.artist->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11]),
880
- ...(*[${typeQuery} brand == "${brand}" &amp;&amp; references(^.genre[]->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11])
885
+ ...(*[_type=="song" &amp;&amp; brand == "${brand}" &amp;&amp; references(^.artist->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11]),
886
+ ...(*[_type=="song" &amp;&amp; brand == "${brand}" &amp;&amp; references(^.genre[]->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11])
881
887
  ])|order(published_on, railcontent_id)[0...11]}`;
882
888
  return fetchSanity(query, false);
883
889
  }
@@ -1041,33 +1047,49 @@ export async function fetchCoachLessons(brand, id, {
1041
1047
  * .catch(error => console.error(error));
1042
1048
  */
1043
1049
  export async function fetchCourseOverview(id) {
1044
- // WIP
1045
1050
  const query = `*[railcontent_id == ${id}]{
1046
- "id": railcontent_id,
1047
- railcontent_id,
1048
- title,
1049
- "image": thumbnail.asset->url,
1050
- "instructors": instructor[]->name,
1051
- difficulty,
1052
- difficulty_string,
1053
- web_url_path,
1054
- published_on,
1055
- "type": _type,
1056
- total_xp,
1057
- xp,
1058
- description,
1059
- resource,
1060
- "lessons": child[]->{
1061
- "id": railcontent_id,
1062
- title,
1063
- "image": thumbnail.asset->url,
1064
- "instructors": instructor[]->name,
1065
- length_in_seconds,
1066
- }
1051
+ ${getFieldsForContentType("course", true)}
1067
1052
  }`
1068
1053
  return fetchSanity(query, false);
1069
1054
  }
1070
1055
 
1056
+ /**
1057
+ * Fetch the data needed for the coach screen.
1058
+ * @param {string} id - The Railcontent ID of the coach
1059
+ *
1060
+ * @returns {Promise&lt;Object|null>} - The lessons for the instructor or null if not found.
1061
+ *
1062
+ * @example
1063
+ * fetchCoachLessons('coach123')
1064
+ * .then(lessons => console.log(lessons))
1065
+ * .catch(error => console.error(error));
1066
+ */
1067
+ export async function fetchByReference(brand, {
1068
+ sortOrder = '-published_on',
1069
+ searchTerm = '',
1070
+ page = 1,
1071
+ limit = 20,
1072
+ includedFields = [],
1073
+ } = {}) {
1074
+ const fieldsString = DEFAULT_FIELDS.join(',');
1075
+ const start = (page - 1) * limit;
1076
+ const end = start + limit;
1077
+ const searchFilter = searchTerm ? `&amp;&amp; title match "${searchTerm}*"`: '';
1078
+ const includedFieldsFilter = includedFields.length > 0
1079
+ ? includedFields.join(' &amp;&amp; ')
1080
+ : "";
1081
+
1082
+ const query = `{
1083
+ "entity": *[brand == '${brand}' ${searchFilter} &amp;&amp; references(*[${includedFieldsFilter}]._id)] | order(${sortOrder}) [${start}...${end}]
1084
+ {
1085
+ ${fieldsString}
1086
+ },
1087
+ "total": count(*[brand == '${brand}' &amp;&amp; references(*[${includedFieldsFilter}]._id)])
1088
+ }`;
1089
+ return fetchSanity(query, true);
1090
+ }
1091
+
1092
+
1071
1093
  /**
1072
1094
  * Fetch data from the Sanity API based on a provided query.
1073
1095
  *
@@ -1191,7 +1213,7 @@ function checkSanityConfig(config) {
1191
1213
  <br class="clear">
1192
1214
 
1193
1215
  <footer>
1194
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Mon Sep 09 2024 19:23:15 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1216
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Wed Sep 11 2024 20:19:27 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1195
1217
  </footer>
1196
1218
 
1197
1219
  <script>prettyPrint();</script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.89",
3
+ "version": "1.0.91",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -75,10 +75,18 @@ let contentTypeConfig = {
75
75
  'course': {
76
76
  'fields': [
77
77
  '"lesson_count": child_count',
78
- '"instructors": instructor[]->name'
78
+ '"instructors": instructor[]->name',
79
+ `"description": ${descriptionField}`,
80
+ 'resource',
81
+ `"lessons": child[]->{
82
+ "id": railcontent_id,
83
+ title,
84
+ "image": thumbnail.asset->url,
85
+ "instructors": instructor[]->name,
86
+ length_in_seconds,
87
+ }`,
79
88
  ]
80
89
  },
81
-
82
90
  'method': {
83
91
  'fields': [
84
92
  `"description": ${descriptionField}`,
@@ -142,18 +142,20 @@ export async function fetchSongsInProgress(brand) {
142
142
  *
143
143
  * @param {string} type - The content type associated with the content.
144
144
  * @param {string} brand - The brand associated with the content.
145
+ * @param {number} [limit=20] - The limit of results per page.
146
+ * @param {number} [page=1] - The page number for pagination.
145
147
  * @returns {Promise<Object|null>} - Returns an object containing in-progress content if found, otherwise null.
146
148
  * @example
147
149
  * fetchContentInProgress('song', 'drumeo')
148
150
  * .then(songs => console.log(songs))
149
151
  * .catch(error => console.error(error));
150
152
  */
151
- export async function fetchContentInProgress(type="all", brand) {
153
+ export async function fetchContentInProgress(type="all", brand, limit=20, page=1) {
152
154
  let url;
153
- if(type!=="all") {
154
- url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?brand=${brand}`;
155
+ if(type !== "all") {
156
+ url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?brand=${brand}&limit=${limit}&page=${page}`;
155
157
  } else {
156
- url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?content_type=${type}&brand=${brand}`;
158
+ url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?content_type=${type}&brand=${brand}&limit=${limit}&page=${page}`;
157
159
  }
158
160
  const headers = {
159
161
  'Content-Type': 'application/json',
@@ -163,7 +165,46 @@ export async function fetchContentInProgress(type="all", brand) {
163
165
  const response = await fetchAbsolute(url, { headers });
164
166
  const result = await response.json();
165
167
  if(result){
166
- console.log('contentInProgress', result);
168
+ //console.log('contentInProgress', result);
169
+ return result;
170
+ } else {
171
+ console.log('result not json');
172
+ }
173
+ } catch (error) {
174
+ console.error('Fetch error:', error);
175
+ return null;
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Fetches a list of content that has been completed for the current user.
181
+ *
182
+ * @param {string} type - The content type associated with the content.
183
+ * @param {string} brand - The brand associated with the content.
184
+ * @param {number} [limit=20] - The limit of results per page.
185
+ * @param {number} [page=1] - The page number for pagination.
186
+ * @returns {Promise<Object|null>} - Returns an object containing in-progress content if found, otherwise null.
187
+ * @example
188
+ * fetchCompletedContent('song', 'drumeo')
189
+ * .then(songs => console.log(songs))
190
+ * .catch(error => console.error(error));
191
+ */
192
+ export async function fetchCompletedContent(type="all", brand, limit=20, page=1) {
193
+ let url;
194
+ if(type !== "all") {
195
+ url = `/content/completed/${globalConfig.railcontentConfig.userId}?brand=${brand}&limit=${limit}&page=${page}`;
196
+ } else {
197
+ url = `/content/completed/${globalConfig.railcontentConfig.userId}?content_type=${type}&brand=${brand}&limit=${limit}&page=${page}`;
198
+ }
199
+ const headers = {
200
+ 'Content-Type': 'application/json',
201
+ 'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
202
+ };
203
+ try {
204
+ const response = await fetchAbsolute(url, { headers });
205
+ const result = await response.json();
206
+ if(result){
207
+ //console.log('completed content', result);
167
208
  return result;
168
209
  } else {
169
210
  console.log('result not json');
@@ -1000,29 +1000,8 @@ export async function fetchCoachLessons(brand, id, {
1000
1000
  * .catch(error => console.error(error));
1001
1001
  */
1002
1002
  export async function fetchCourseOverview(id) {
1003
- // WIP
1004
1003
  const query = `*[railcontent_id == ${id}]{
1005
- "id": railcontent_id,
1006
- railcontent_id,
1007
- title,
1008
- "image": thumbnail.asset->url,
1009
- "instructors": instructor[]->name,
1010
- difficulty,
1011
- difficulty_string,
1012
- web_url_path,
1013
- published_on,
1014
- "type": _type,
1015
- total_xp,
1016
- xp,
1017
- description,
1018
- resource,
1019
- "lessons": child[]->{
1020
- "id": railcontent_id,
1021
- title,
1022
- "image": thumbnail.asset->url,
1023
- "instructors": instructor[]->name,
1024
- length_in_seconds,
1025
- }
1004
+ ${getFieldsForContentType("course", true)}
1026
1005
  }`
1027
1006
  return fetchSanity(query, false);
1028
1007
  }