musora-content-services 1.0.86 → 1.0.88
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/index.js +2 -0
- package/src/services/config.js +4 -1
- package/src/services/railcontent.js +15 -6
- package/src/services/sanity.js +50 -8
- package/test/sanityQueryService.test.js +9 -2
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.88](https://github.com/railroadmedia/musora-content-services/compare/v1.0.87...v1.0.88) (2024-09-11)
|
|
6
|
+
|
|
7
|
+
### [1.0.87](https://github.com/railroadmedia/musora-content-services/compare/v1.0.86...v1.0.87) (2024-09-09)
|
|
8
|
+
|
|
5
9
|
### [1.0.86](https://github.com/railroadmedia/musora-content-services/compare/v1.0.85...v1.0.86) (2024-09-09)
|
|
6
10
|
|
|
7
11
|
### [1.0.85](https://github.com/railroadmedia/musora-content-services/compare/v1.0.84...v1.0.85) (2024-09-06)
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
fetchLiveEvent,
|
|
35
35
|
fetchChallengeOverview,
|
|
36
36
|
fetchCoachLessons,
|
|
37
|
+
fetchByReference,
|
|
37
38
|
} from './services/sanity.js';
|
|
38
39
|
|
|
39
40
|
import {
|
|
@@ -85,4 +86,5 @@ export {
|
|
|
85
86
|
fetchVimeoData,
|
|
86
87
|
fetchContentPageUserData,
|
|
87
88
|
fetchCoachLessons,
|
|
89
|
+
fetchByReference,
|
|
88
90
|
}
|
package/src/services/config.js
CHANGED
|
@@ -22,6 +22,8 @@ let globalConfig = {
|
|
|
22
22
|
* @param {Object} config.railcontentConfig - Configuration for user services.
|
|
23
23
|
* @param {string} config.railcontentConfig.token - The token for authenticating user-specific requests.
|
|
24
24
|
* @param {string} config.railcontentConfig.userId - The user ID for fetching user-specific data.
|
|
25
|
+
* @param {string} config.railcontentConfig.baseUrl - The url for the enviroment.
|
|
26
|
+
|
|
25
27
|
*
|
|
26
28
|
* @example
|
|
27
29
|
* // Initialize the service in your app.js
|
|
@@ -36,7 +38,8 @@ let globalConfig = {
|
|
|
36
38
|
* },
|
|
37
39
|
* railcontentConfig: {
|
|
38
40
|
* token: 'your-user-api-token',
|
|
39
|
-
* userId: 'current-user-id'
|
|
41
|
+
* userId: 'current-user-id',
|
|
42
|
+
* baseUrl: 'https://web-staging-one.musora.com'
|
|
40
43
|
* }
|
|
41
44
|
* });
|
|
42
45
|
*/
|
|
@@ -24,7 +24,7 @@ export async function fetchCompletedState(content_id) {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
try {
|
|
27
|
-
const response = await
|
|
27
|
+
const response = await fetchAbsolute(url, { headers });
|
|
28
28
|
const result = await response.json();
|
|
29
29
|
|
|
30
30
|
if (result && result[content_id]) { return result[content_id]; // Return the correct object
|
|
@@ -56,7 +56,7 @@ export async function fetchVimeoData(vimeo_id) {
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
try {
|
|
59
|
-
const response = await
|
|
59
|
+
const response = await fetchAbsolute(url, { headers });
|
|
60
60
|
const result = await response.json();
|
|
61
61
|
|
|
62
62
|
if (result) {
|
|
@@ -91,7 +91,7 @@ export async function fetchAllCompletedStates(contentIds) {
|
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
try {
|
|
94
|
-
const response = await
|
|
94
|
+
const response = await fetchAbsolute(url, { headers });
|
|
95
95
|
const result = await response.json();
|
|
96
96
|
if(result){
|
|
97
97
|
return result;
|
|
@@ -123,7 +123,7 @@ export async function fetchSongsInProgress(brand) {
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
try {
|
|
126
|
-
const response = await
|
|
126
|
+
const response = await fetchAbsolute(url, { headers });
|
|
127
127
|
const result = await response.json();
|
|
128
128
|
if(result){
|
|
129
129
|
console.log('fetchSongsInProgress', result);
|
|
@@ -160,7 +160,7 @@ export async function fetchContentInProgress(type="all", brand) {
|
|
|
160
160
|
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
161
161
|
};
|
|
162
162
|
try {
|
|
163
|
-
const response = await
|
|
163
|
+
const response = await fetchAbsolute(url, { headers });
|
|
164
164
|
const result = await response.json();
|
|
165
165
|
if(result){
|
|
166
166
|
console.log('contentInProgress', result);
|
|
@@ -191,8 +191,9 @@ export async function fetchContentPageUserData(contentId) {
|
|
|
191
191
|
'Content-Type': 'application/json',
|
|
192
192
|
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
193
193
|
};
|
|
194
|
+
|
|
194
195
|
try {
|
|
195
|
-
const response = await
|
|
196
|
+
const response = await fetchAbsolute(url, { headers });
|
|
196
197
|
const result = await response.json();
|
|
197
198
|
if(result){
|
|
198
199
|
console.log('fetchContentPageUserData', result);
|
|
@@ -204,4 +205,12 @@ export async function fetchContentPageUserData(contentId) {
|
|
|
204
205
|
console.error('Fetch error:', error);
|
|
205
206
|
return null;
|
|
206
207
|
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function fetchAbsolute(url, params) {
|
|
211
|
+
if (url.startsWith('/')) {
|
|
212
|
+
return fetch(globalConfig.railcontentConfig.baseUrl + url, params)
|
|
213
|
+
} else {
|
|
214
|
+
return fetch(url, params);
|
|
215
|
+
}
|
|
207
216
|
}
|
package/src/services/sanity.js
CHANGED
|
@@ -224,7 +224,7 @@ export async function fetchSongFilterOptions(brand) {
|
|
|
224
224
|
*/
|
|
225
225
|
export async function fetchSongCount(brand) {
|
|
226
226
|
const query = `count(*[_type == 'song' && brand == "${brand}"])`;
|
|
227
|
-
return fetchSanity(query,
|
|
227
|
+
return fetchSanity(query, true);
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
/**
|
|
@@ -812,7 +812,9 @@ export async function fetchLessonContent(railContentId) {
|
|
|
812
812
|
"instructors":instructor[]->name,
|
|
813
813
|
instructor[]->,
|
|
814
814
|
${assignmentsField}
|
|
815
|
-
|
|
815
|
+
video,
|
|
816
|
+
length_in_seconds
|
|
817
|
+
}`
|
|
816
818
|
return fetchSanity(query, false);
|
|
817
819
|
}
|
|
818
820
|
|
|
@@ -820,17 +822,20 @@ export async function fetchLessonContent(railContentId) {
|
|
|
820
822
|
* Fetch related lessons for a specific lesson by RailContent ID and type.
|
|
821
823
|
* @param {string} railContentId - The RailContent ID of the current lesson.
|
|
822
824
|
* @param {string} brand - The current brand.
|
|
823
|
-
* @param {string} contentType - name of the contentype to pull
|
|
824
825
|
* @returns {Promise<Array<Object>|null>} - The fetched related lessons data or null if not found.
|
|
825
826
|
*/
|
|
826
|
-
export async function fetchRelatedLessons(railContentId, brand
|
|
827
|
-
let
|
|
828
|
-
|
|
827
|
+
export async function fetchRelatedLessons(railContentId, brand) {
|
|
828
|
+
// let sort = 'published_on'
|
|
829
|
+
// if (type == 'rhythmic-adventures-of-captain-carson' ||
|
|
830
|
+
// type == 'diy-drum-experiments' ||
|
|
831
|
+
// type == 'in-rhythm') {
|
|
832
|
+
// sort = 'sort';
|
|
833
|
+
// }
|
|
829
834
|
//TODO: Implement $this->contentService->getFiltered
|
|
830
835
|
const query = `*[railcontent_id == ${railContentId} && brand == "${brand}" && references(*[_type=='permission']._id)]{
|
|
831
836
|
"related_lessons" : array::unique([
|
|
832
|
-
|
|
833
|
-
...(*[
|
|
837
|
+
...(*[_type=="song" && brand == "${brand}" && references(^.artist->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11]),
|
|
838
|
+
...(*[_type=="song" && brand == "${brand}" && references(^.genre[]->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11])
|
|
834
839
|
])|order(published_on, railcontent_id)[0...11]}`;
|
|
835
840
|
return fetchSanity(query, false);
|
|
836
841
|
}
|
|
@@ -1021,6 +1026,43 @@ export async function fetchCourseOverview(id) {
|
|
|
1021
1026
|
return fetchSanity(query, false);
|
|
1022
1027
|
}
|
|
1023
1028
|
|
|
1029
|
+
/**
|
|
1030
|
+
* Fetch the data needed for the coach screen.
|
|
1031
|
+
* @param {string} id - The Railcontent ID of the coach
|
|
1032
|
+
*
|
|
1033
|
+
* @returns {Promise<Object|null>} - The lessons for the instructor or null if not found.
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* fetchCoachLessons('coach123')
|
|
1037
|
+
* .then(lessons => console.log(lessons))
|
|
1038
|
+
* .catch(error => console.error(error));
|
|
1039
|
+
*/
|
|
1040
|
+
export async function fetchByReference(brand, {
|
|
1041
|
+
sortOrder = '-published_on',
|
|
1042
|
+
searchTerm = '',
|
|
1043
|
+
page = 1,
|
|
1044
|
+
limit = 20,
|
|
1045
|
+
includedFields = [],
|
|
1046
|
+
} = {}) {
|
|
1047
|
+
const fieldsString = DEFAULT_FIELDS.join(',');
|
|
1048
|
+
const start = (page - 1) * limit;
|
|
1049
|
+
const end = start + limit;
|
|
1050
|
+
const searchFilter = searchTerm ? `&& title match "${searchTerm}*"`: '';
|
|
1051
|
+
const includedFieldsFilter = includedFields.length > 0
|
|
1052
|
+
? includedFields.join(' && ')
|
|
1053
|
+
: "";
|
|
1054
|
+
|
|
1055
|
+
const query = `{
|
|
1056
|
+
"entity": *[brand == '${brand}' ${searchFilter} && references(*[${includedFieldsFilter}]._id)] | order(${sortOrder}) [${start}...${end}]
|
|
1057
|
+
{
|
|
1058
|
+
${fieldsString}
|
|
1059
|
+
},
|
|
1060
|
+
"total": count(*[brand == '${brand}' && references(*[${includedFieldsFilter}]._id)])
|
|
1061
|
+
}`;
|
|
1062
|
+
return fetchSanity(query, true);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
|
|
1024
1066
|
/**
|
|
1025
1067
|
* Fetch data from the Sanity API based on a provided query.
|
|
1026
1068
|
*
|
|
@@ -31,6 +31,7 @@ const {
|
|
|
31
31
|
fetchAllPacks,
|
|
32
32
|
fetchPacksAll,
|
|
33
33
|
fetchCoachLessons,
|
|
34
|
+
fetchByReference,
|
|
34
35
|
} = require('../src/services/sanity.js');
|
|
35
36
|
|
|
36
37
|
describe('Sanity Queries', function () {
|
|
@@ -158,7 +159,7 @@ describe('Sanity Queries', function () {
|
|
|
158
159
|
const id = 380094;
|
|
159
160
|
const document = await fetchByRailContentId(id);
|
|
160
161
|
let artist = document.artist.name;
|
|
161
|
-
const response = await fetchRelatedLessons(id, 'singeo'
|
|
162
|
+
const response = await fetchRelatedLessons(id, 'singeo');
|
|
162
163
|
let relatedDoc = await fetchByRailContentId(response.related_lessons[0].id);
|
|
163
164
|
// match on artist or any genre
|
|
164
165
|
let isMatch = artist === relatedDoc.artist.name;
|
|
@@ -270,6 +271,7 @@ describe('Sanity Queries', function () {
|
|
|
270
271
|
response = await fetchAllPacks('drumeo', 'slug', 'Creative Control');
|
|
271
272
|
expect(response[0].id).toBe(212899);
|
|
272
273
|
});
|
|
274
|
+
|
|
273
275
|
test('fetchCoachLessons', async () => {
|
|
274
276
|
const response = await fetchCoachLessons('drumeo',233797);
|
|
275
277
|
expect(response.entity.length).toBeGreaterThan(0);
|
|
@@ -277,6 +279,11 @@ describe('Sanity Queries', function () {
|
|
|
277
279
|
|
|
278
280
|
test('fetchAll-IncludedFields', async () => {
|
|
279
281
|
let response = await fetchAll('drumeo', 'instructor',{includedFields: ['is_active']});
|
|
280
|
-
|
|
282
|
+
expect(response.entity.length).toBeGreaterThan(0);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('fetchByReference', async () => {
|
|
286
|
+
const response = await fetchByReference('drumeo', { includedFields: ['is_featured'] });
|
|
287
|
+
expect(response.entity.length).toBeGreaterThan(0);
|
|
281
288
|
});
|
|
282
289
|
});
|