musora-content-services 1.0.28 → 1.0.30
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 +4 -0
- package/package.json +1 -1
- package/src/services/sanity.js +17 -57
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.30](https://github.com/railroadmedia/musora-content-services/compare/v1.0.29...v1.0.30) (2024-08-14)
|
|
6
|
+
|
|
7
|
+
### [1.0.29](https://github.com/railroadmedia/musora-content-services/compare/v1.0.28...v1.0.29) (2024-08-14)
|
|
8
|
+
|
|
5
9
|
### [1.0.28](https://github.com/railroadmedia/musora-content-services/compare/v1.0.27...v1.0.28) (2024-08-14)
|
|
6
10
|
|
|
7
11
|
### [1.0.27](https://github.com/railroadmedia/musora-content-services/compare/v1.0.26...v1.0.27) (2024-08-14)
|
package/package.json
CHANGED
package/src/services/sanity.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
48
|
-
return songData;
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error('Error fetching song by ID:', error);
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
38
|
+
return fetchSanity(query, false);
|
|
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
|
-
|
|
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, false);
|
|
190
150
|
}
|
|
191
151
|
|
|
192
152
|
/**
|