musora-content-services 1.0.76 → 1.0.77

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/src/index.js CHANGED
@@ -30,10 +30,11 @@ import {
30
30
  fetchParentByRailContentId,
31
31
  fetchMethodPreviousNextLesson,
32
32
  fetchLiveEvent,
33
+ fetchChallengeOverview,
33
34
  } from './services/sanity.js';
34
35
 
35
36
  import {
36
- fetchCurrentSongComplete,
37
+ fetchCompletedState,
37
38
  fetchAllCompletedStates,
38
39
  fetchContentInProgress
39
40
  } from './services/railcontent.js';
@@ -65,7 +66,7 @@ export {
65
66
  fetchPackAll,
66
67
  fetchPackChildren,
67
68
  fetchLessonContent,
68
- fetchCurrentSongComplete,
69
+ fetchCompletedState,
69
70
  fetchAllCompletedStates,
70
71
  fetchContentInProgress,
71
72
  fetchCourseOverview,
@@ -73,4 +74,5 @@ export {
73
74
  fetchParentByRailContentId,
74
75
  fetchMethodPreviousNextLesson,
75
76
  fetchLiveEvent,
77
+ fetchChallengeOverview,
76
78
  }
@@ -4,17 +4,18 @@
4
4
 
5
5
  const { globalConfig } = require('./config');
6
6
 
7
+
7
8
  /**
8
- * Fetches the completion status of a specific song for the current user.
9
+ * Fetches the completion status of a specific lesson for the current user.
9
10
  *
10
- * @param {string} content_id - The ID of the song content to check.
11
+ * @param {string} content_id - The ID of the lesson content to check.
11
12
  * @returns {Promise<Object|null>} - Returns the completion status object if found, otherwise null.
12
13
  * @example
13
- * fetchCurrentSongComplete('user123', 'song456', 'csrf-token')
14
+ * fetchCurrentSongComplete('user123', 'lesson456', 'csrf-token')
14
15
  * .then(status => console.log(status))
15
16
  * .catch(error => console.error(error));
16
17
  */
17
- export async function fetchCurrentSongComplete(content_id) {
18
+ export async function fetchCompletedState(content_id) {
18
19
  const url = `/content/user_progress/${globalConfig.railcontentConfig.userId}?content_ids[]=${content_id}`;
19
20
 
20
21
  const headers = {
@@ -26,11 +27,8 @@ export async function fetchCurrentSongComplete(content_id) {
26
27
  const response = await fetch(url, { headers });
27
28
  const result = await response.json();
28
29
 
29
- if (result && result[content_id]) {
30
- console.log('result', result[content_id]);
31
- return result[content_id]; // Return the correct object
30
+ if (result && result[content_id]) { return result[content_id]; // Return the correct object
32
31
  } else {
33
- console.log('Invalid result structure', result);
34
32
  return null; // Handle unexpected structure
35
33
  }
36
34
  } catch (error) {
@@ -639,6 +639,7 @@ return fetchSanity(query, false);
639
639
  export async function fetchMethodChildren(railcontentId) {
640
640
  const query = `*[railcontent_id == ${railcontentId}]{
641
641
  child_count,
642
+ "id": railcontent_id,
642
643
  "description": ${descriptionField},
643
644
  title,
644
645
  xp,
@@ -815,8 +816,9 @@ export async function fetchRelatedLessons(railContentId, brand) {
815
816
  */
816
817
  export async function fetchPackAll(railcontentId) {
817
818
  //TODO: Implement getPacks
818
- const query = `*[_railcontent_id == ${railcontentId}]{
819
+ const query = `*[railcontent_id == ${railcontentId}]{
819
820
  railcontent_id,
821
+ "id": railcontent_id,
820
822
  title,
821
823
  "image": thumbnail.asset->url,
822
824
  "artist_name": artist->name,
@@ -886,6 +888,34 @@ export async function fetchPackChildren(railcontentId) {
886
888
  return fetchChildren(railcontentId, 'pack');
887
889
  }
888
890
 
891
+ /**
892
+ * Fetch the data needed for the Challenge Overview screen.
893
+ * @param {string} id - The Railcontent ID of the course
894
+ * @returns {Promise<Object|null>} - The challenge information and lessons or null if not found.
895
+ *
896
+ * @example
897
+ * fetchChallengeOverview('challenge123')
898
+ * .then(challenge => console.log(challenge))
899
+ * .catch(error => console.error(error));
900
+ */
901
+ export async function fetchChallengeOverview(id) {
902
+ // WIP
903
+ const query = `*[railcontent_id == ${id}]{
904
+ ${getFieldsForContentType("challenge", true)}
905
+ "lessons": child[]->{
906
+ "id": railcontent_id,
907
+ title,
908
+ "image": thumbnail.asset->url,
909
+ "instructors": instructor[]->name,
910
+ length_in_seconds,
911
+ difficulty_string,
912
+ difficulty,
913
+ "type": _type,
914
+ }
915
+ }`;
916
+ return fetchSanity(query, false);
917
+ }
918
+
889
919
  /**
890
920
  * Fetch the data needed for the Course Overview screen.
891
921
  * @param {string} id - The Railcontent ID of the course
@@ -109,6 +109,21 @@ describe('Sanity Queries', function () {
109
109
  expect(response.entity[0].id).toBeDefined();
110
110
  });
111
111
 
112
+ test('fetchAllInstructorField', async () => {
113
+ const response = await fetchAll('drumeo', 'quick-tips',{searchTerm: 'Domino Santantonio'});
114
+ console.log(response);
115
+ expect(response.entity[0].id).toBeDefined();
116
+ expect(response.entity[0].instructors).toBeTruthy();
117
+ });
118
+
119
+ test('fetchAllSortField', async () => {
120
+ const response = await fetchAll('drumeo', 'rhythmic-adventures-of-captain-carson',{});
121
+ console.log(response);
122
+ expect(response.entity[0].id).toBeDefined();
123
+ expect(response.entity[0].sort).toBeDefined();
124
+ });
125
+
126
+
112
127
  test('fetchAllChallenges', async () => {
113
128
  const response = await fetchAll('drumeo', 'challenge',{});
114
129
  console.log(response);