musora-content-services 1.0.188 → 1.0.190
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.d.ts +4 -0
- package/src/index.js +4 -0
- package/src/services/railcontent.js +21 -0
- package/src/services/sanity.js +54 -0
- package/test/sanityQueryService.test.js +13 -0
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.190](https://github.com/railroadmedia/musora-content-services/compare/v1.0.189...v1.0.190) (2024-11-28)
|
|
6
|
+
|
|
7
|
+
### [1.0.189](https://github.com/railroadmedia/musora-content-services/compare/v1.0.188...v1.0.189) (2024-11-28)
|
|
8
|
+
|
|
5
9
|
### [1.0.188](https://github.com/railroadmedia/musora-content-services/compare/v1.0.187...v1.0.188) (2024-11-28)
|
|
6
10
|
|
|
7
11
|
### [1.0.187](https://github.com/railroadmedia/musora-content-services/compare/v1.0.186...v1.0.187) (2024-11-28)
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
deletePlaylistLike,
|
|
37
37
|
duplicatePlaylist,
|
|
38
38
|
fetchAllCompletedStates,
|
|
39
|
+
fetchCarouselCardData,
|
|
39
40
|
fetchChallengeIndexMetadata,
|
|
40
41
|
fetchChallengeLessonData,
|
|
41
42
|
fetchChallengeMetadata,
|
|
@@ -65,6 +66,7 @@ import {
|
|
|
65
66
|
postChallengesCompleteLesson,
|
|
66
67
|
postChallengesEnroll,
|
|
67
68
|
postChallengesEnrollmentNotification,
|
|
69
|
+
postChallengesHideCompletedBanner,
|
|
68
70
|
postChallengesLeave,
|
|
69
71
|
postChallengesSetStartDate,
|
|
70
72
|
postChallengesUnlock,
|
|
@@ -159,6 +161,7 @@ declare module 'musora-content-services' {
|
|
|
159
161
|
fetchByRailContentId,
|
|
160
162
|
fetchByRailContentIds,
|
|
161
163
|
fetchByReference,
|
|
164
|
+
fetchCarouselCardData,
|
|
162
165
|
fetchCatalogMetadata,
|
|
163
166
|
fetchChallengeIndexMetadata,
|
|
164
167
|
fetchChallengeLessonData,
|
|
@@ -240,6 +243,7 @@ declare module 'musora-content-services' {
|
|
|
240
243
|
postChallengesCompleteLesson,
|
|
241
244
|
postChallengesEnroll,
|
|
242
245
|
postChallengesEnrollmentNotification,
|
|
246
|
+
postChallengesHideCompletedBanner,
|
|
243
247
|
postChallengesLeave,
|
|
244
248
|
postChallengesSetStartDate,
|
|
245
249
|
postChallengesUnlock,
|
package/src/index.js
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
deletePlaylistLike,
|
|
37
37
|
duplicatePlaylist,
|
|
38
38
|
fetchAllCompletedStates,
|
|
39
|
+
fetchCarouselCardData,
|
|
39
40
|
fetchChallengeIndexMetadata,
|
|
40
41
|
fetchChallengeLessonData,
|
|
41
42
|
fetchChallengeMetadata,
|
|
@@ -65,6 +66,7 @@ import {
|
|
|
65
66
|
postChallengesCompleteLesson,
|
|
66
67
|
postChallengesEnroll,
|
|
67
68
|
postChallengesEnrollmentNotification,
|
|
69
|
+
postChallengesHideCompletedBanner,
|
|
68
70
|
postChallengesLeave,
|
|
69
71
|
postChallengesSetStartDate,
|
|
70
72
|
postChallengesUnlock,
|
|
@@ -158,6 +160,7 @@ export {
|
|
|
158
160
|
fetchByRailContentId,
|
|
159
161
|
fetchByRailContentIds,
|
|
160
162
|
fetchByReference,
|
|
163
|
+
fetchCarouselCardData,
|
|
161
164
|
fetchCatalogMetadata,
|
|
162
165
|
fetchChallengeIndexMetadata,
|
|
163
166
|
fetchChallengeLessonData,
|
|
@@ -239,6 +242,7 @@ export {
|
|
|
239
242
|
postChallengesCompleteLesson,
|
|
240
243
|
postChallengesEnroll,
|
|
241
244
|
postChallengesEnrollmentNotification,
|
|
245
|
+
postChallengesHideCompletedBanner,
|
|
242
246
|
postChallengesLeave,
|
|
243
247
|
postChallengesSetStartDate,
|
|
244
248
|
postChallengesUnlock,
|
|
@@ -412,6 +412,16 @@ export async function fetchChallengeUserActiveChallenges(brand = null) {
|
|
|
412
412
|
return await fetchHandler(url, 'get');
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Fetch All Carousel Card Data
|
|
417
|
+
*
|
|
418
|
+
* @returns {Promise<any|null>}
|
|
419
|
+
*/
|
|
420
|
+
export async function fetchCarouselCardData() {
|
|
421
|
+
let url = `/api/v1/content/carousel`;
|
|
422
|
+
return await fetchHandler(url, 'get');
|
|
423
|
+
}
|
|
424
|
+
|
|
415
425
|
/**
|
|
416
426
|
* Fetch all completed badges for the user ordered by completion date descending
|
|
417
427
|
*
|
|
@@ -507,6 +517,17 @@ export async function postChallengesCompleteLesson(contentId) {
|
|
|
507
517
|
return await fetchHandler(url, 'post');
|
|
508
518
|
}
|
|
509
519
|
|
|
520
|
+
/**
|
|
521
|
+
* Hide challenge completed award bannare
|
|
522
|
+
*
|
|
523
|
+
* @param {int|string} contentId - railcontent id of the challenge
|
|
524
|
+
* @returns {Promise<any|null>}
|
|
525
|
+
*/
|
|
526
|
+
export async function postChallengesHideCompletedBanner(contentId) {
|
|
527
|
+
let url = `/challenges/hide_completed_banner/${contentId}`;
|
|
528
|
+
return await fetchHandler(url, 'post');
|
|
529
|
+
}
|
|
530
|
+
|
|
510
531
|
/**
|
|
511
532
|
* Fetches user playlists for a specific brand.
|
|
512
533
|
*
|
package/src/services/sanity.js
CHANGED
|
@@ -635,11 +635,65 @@ async function handleCustomFetchAll(brand, type, {
|
|
|
635
635
|
return fetchCompletedChallenges(brand, page, limit);
|
|
636
636
|
} else if (groupBy === 'owned') {
|
|
637
637
|
return fetchOwnedChallenges(brand, page, limit);
|
|
638
|
+
} else if (groupBy === 'difficulty_string') {
|
|
639
|
+
return fetchChallengesByDifficulty(brand, type, page, limit, searchTerm, sort, includedFields, groupBy, progressIds, useDefaultFields, customFields, progress);
|
|
638
640
|
}
|
|
639
641
|
}
|
|
640
642
|
return null;
|
|
641
643
|
}
|
|
642
644
|
|
|
645
|
+
async function fetchChallengesByDifficulty(brand, type, page, limit, searchTerm, sort, includedFields, groupBy, progressIds, useDefaultFields, customFields, progress) {
|
|
646
|
+
let config = contentTypeConfig['challenge'] ?? {};
|
|
647
|
+
let additionalFields = config?.fields ?? [];
|
|
648
|
+
|
|
649
|
+
// Construct the search filter
|
|
650
|
+
const searchFilter = searchTerm
|
|
651
|
+
? groupBy !== "" ?
|
|
652
|
+
`&& (^.name match "${searchTerm}*" || title match "${searchTerm}*")`
|
|
653
|
+
: `&& (artist->name match "${searchTerm}*" || instructor[]->name match "${searchTerm}*" || title match "${searchTerm}*" || name match "${searchTerm}*")`
|
|
654
|
+
: "";
|
|
655
|
+
|
|
656
|
+
// Construct the included fields filter, replacing 'difficulty' with 'difficulty_string'
|
|
657
|
+
const includedFieldsFilter = includedFields.length > 0
|
|
658
|
+
? filtersToGroq(includedFields)
|
|
659
|
+
: "";
|
|
660
|
+
|
|
661
|
+
// limits the results to supplied progressIds for started & completed filters
|
|
662
|
+
const progressFilter = await getProgressFilter(progress, progressIds);
|
|
663
|
+
|
|
664
|
+
let fields = useDefaultFields ? customFields.concat(DEFAULT_FIELDS, additionalFields) : customFields;
|
|
665
|
+
let fieldsString = fields.join(',');
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
const lessonsFilter = `_type == 'challenge' && brand == '${brand}' && ^.name == difficulty_string ${searchFilter} ${includedFieldsFilter} ${progressFilter}`;
|
|
669
|
+
const lessonsFilterWithRestrictions = await new FilterBuilder(lessonsFilter).buildFilter();
|
|
670
|
+
|
|
671
|
+
const query = `{
|
|
672
|
+
"entity": [
|
|
673
|
+
{"name": "All"},
|
|
674
|
+
{"name": "Novice"},
|
|
675
|
+
{"name": "Beginner"},
|
|
676
|
+
{"name": "Intermediate"},
|
|
677
|
+
{"name": "Advanced"},
|
|
678
|
+
{"name": "Expert"}]
|
|
679
|
+
{
|
|
680
|
+
'id': 0,
|
|
681
|
+
name,
|
|
682
|
+
'all_lessons_count': count(*[${lessonsFilterWithRestrictions}]._id),
|
|
683
|
+
'lessons': *[${lessonsFilterWithRestrictions}]{
|
|
684
|
+
${fieldsString},
|
|
685
|
+
name
|
|
686
|
+
}[0...20]
|
|
687
|
+
},
|
|
688
|
+
"total": 0
|
|
689
|
+
}`;
|
|
690
|
+
let data = await fetchSanity(query, true);
|
|
691
|
+
data.entity = data.entity.filter(function(difficulty){
|
|
692
|
+
return difficulty.lessons.length > 0;
|
|
693
|
+
});
|
|
694
|
+
return data;
|
|
695
|
+
}
|
|
696
|
+
|
|
643
697
|
async function getProgressFilter(progress, progressIds) {
|
|
644
698
|
switch (progress) {
|
|
645
699
|
case "all":
|
|
@@ -256,6 +256,19 @@ describe('Sanity Queries', function () {
|
|
|
256
256
|
|
|
257
257
|
});
|
|
258
258
|
|
|
259
|
+
test('fetchAllChallengesByGenre', async () => {
|
|
260
|
+
const response = await fetchAll('drumeo', 'challenge', {groupBy:'genre'});
|
|
261
|
+
expect(response.entity[0].type).toBe('genre');
|
|
262
|
+
expect(response.entity[0].lessons).toBeDefined();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('fetchAllChallengesByDifficulty', async () => {
|
|
266
|
+
const response = await fetchAll('drumeo', 'challenge', {groupBy:'difficulty_string'});
|
|
267
|
+
expect(response.entity[0].name).toBeDefined();
|
|
268
|
+
expect(response.entity[0].lessons).toBeDefined();
|
|
269
|
+
expect(response.entity[0].lessons.length).toBeGreaterThan(0)
|
|
270
|
+
});
|
|
271
|
+
|
|
259
272
|
test('fetchAll-CustomFields', async () => {
|
|
260
273
|
let response = await fetchAll('drumeo', 'challenge', {customFields: ['garbage']});
|
|
261
274
|
log(response);
|