musora-content-services 1.0.27 → 1.0.29

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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.29](https://github.com/railroadmedia/musora-content-services/compare/v1.0.28...v1.0.29) (2024-08-14)
6
+
7
+ ### [1.0.28](https://github.com/railroadmedia/musora-content-services/compare/v1.0.27...v1.0.28) (2024-08-14)
8
+
5
9
  ### [1.0.27](https://github.com/railroadmedia/musora-content-services/compare/v1.0.26...v1.0.27) (2024-08-14)
6
10
 
7
11
  ### [1.0.26](https://github.com/railroadmedia/musora-content-services/compare/v1.0.25...v1.0.26) (2024-08-14)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -18,7 +18,6 @@ const { globalConfig } = require('./config');
18
18
  */
19
19
  export async function fetchCurrentSongComplete(content_id) {
20
20
  const url = `/content/user_progress/${globalConfig.railcontentConfig.userId}?content_ids[]=${content_id}`;
21
- console.log('Request URL:', url); // Debugging log
22
21
 
23
22
  const headers = {
24
23
  'Content-Type': 'application/json',
@@ -27,13 +26,14 @@ export async function fetchCurrentSongComplete(content_id) {
27
26
 
28
27
  try {
29
28
  const response = await fetch(url, { headers });
30
- if (!response.ok) {
31
- throw new Error(`HTTP error! status: ${response.status}`);
32
- }
33
29
  const result = await response.json();
34
- if (result) {
35
- console.log('API result:', result);
36
- return result[globalConfig.railcontentConfig.userId];
30
+
31
+ if (result && result[content_id]) {
32
+ console.log('result', result[content_id]);
33
+ return result[content_id]; // Return the correct object
34
+ } else {
35
+ console.log('Invalid result structure', result);
36
+ return null; // Handle unexpected structure
37
37
  }
38
38
  } catch (error) {
39
39
  console.error('Fetch error:', error);
@@ -41,6 +41,7 @@ export async function fetchCurrentSongComplete(content_id) {
41
41
  }
42
42
  }
43
43
 
44
+
44
45
  /**
45
46
  * Fetches the completion status for multiple songs for the current user.
46
47
  *
@@ -18,41 +18,26 @@ import { fetchAllCompletedStates, fetchCurrentSongComplete } from './railcontent
18
18
  * .then(song => console.log(song))
19
19
  * .catch(error => console.error(error));
20
20
  */
21
- export async function fetchSongById(songId) {
21
+ export async function fetchSongById(documentId) {
22
+ const fields = [
23
+ 'title',
24
+ '"thumbnail_url": thumbnail.asset->url',
25
+ '"style": genre[0]->name',
26
+ '"artist": artist->name',
27
+ 'album',
28
+ 'instrumentless',
29
+ 'soundslice',
30
+ '"resources": resource[]{resource_url, resource_name}',
31
+ ];
32
+
22
33
  const query = `
23
- *[_type == "song" && railcontent_id == ${songId}]{
24
- title,
25
- "thumbnail_url": thumbnail.asset->url,
26
- "style": genre[0]->name,
27
- "artist": artist->name,
28
- album,
29
- instrumentless,
30
- soundslice,
31
- railcontent_id,
32
- "resources": resource[]{resource_url, resource_name},
33
- }`;
34
-
35
- try {
36
- const songData = await fetchSanity(query, false);
37
- const currentSongComplete = await fetchCurrentSongComplete(songId);
38
-
39
- if (songData && currentSongComplete) {
40
- console.log('currentSongComplete', currentSongComplete);
41
- songData.completed = currentSongComplete.state !== "not started";
42
- songData.progress_percent = currentSongComplete.percent.toString();
43
- } else {
44
- console.log('no currentSongComplete', currentSongComplete);
45
- }
34
+ *[_type == "song" && railcontent_id == ${documentId}]{
35
+ ${fields.join(', ')}
36
+ }`;
46
37
 
47
- console.log('all songData', songData);
48
- return songData;
49
- } catch (error) {
50
- console.error('Error fetching song by ID:', error);
51
- return null;
52
- }
38
+ return fetchSanity(query, true);
53
39
  }
54
40
 
55
-
56
41
  /**
57
42
  * Fetch all artists with lessons available for a specific brand.
58
43
  *
@@ -161,32 +146,7 @@ export async function fetchRelatedSongs(brand, songId) {
161
146
  }`;
162
147
 
163
148
  // Fetch the related songs data
164
- const relatedSongsData = await fetchSanity(query, true);
165
-
166
- if (!relatedSongsData || !userId || !token) {
167
- return relatedSongsData;
168
- }
169
-
170
- // Extract the IDs of related lessons
171
- const relatedLessonIds = relatedSongsData.data.map(lesson => lesson.id);
172
-
173
- // Fetch the completion states for the related lessons
174
- const relatedLessonsCompletionStates = await fetchAllCompletedStates(relatedLessonIds);
175
-
176
- // Map the completion states to the related lessons
177
- relatedSongsData.data = relatedSongsData.data.map(lesson => {
178
- const lessonCompletionState = relatedLessonsCompletionStates[lesson.id];
179
- if (lessonCompletionState) {
180
- return {
181
- ...lesson,
182
- completed: lessonCompletionState.state !== "not started",
183
- lesson_progress: lessonCompletionState.percent.toString()
184
- };
185
- }
186
- return lesson;
187
- });
188
-
189
- return relatedSongsData;
149
+ return fetchSanity(query, true);
190
150
  }
191
151
 
192
152
  /**