musora-content-services 1.0.189 → 1.0.191

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.191](https://github.com/railroadmedia/musora-content-services/compare/v1.0.190...v1.0.191) (2024-11-28)
6
+
7
+ ### [1.0.190](https://github.com/railroadmedia/musora-content-services/compare/v1.0.189...v1.0.190) (2024-11-28)
8
+
5
9
  ### [1.0.189](https://github.com/railroadmedia/musora-content-services/compare/v1.0.188...v1.0.189) (2024-11-28)
6
10
 
7
11
  ### [1.0.188](https://github.com/railroadmedia/musora-content-services/compare/v1.0.187...v1.0.188) (2024-11-28)
package/README.md CHANGED
File without changes
package/jest.config.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.189",
3
+ "version": "1.0.191",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
File without changes
File without changes
File without changes
@@ -632,14 +632,94 @@ async function handleCustomFetchAll(brand, type, {
632
632
  } = {}) {
633
633
  if (type === 'challenge') {
634
634
  if (groupBy === 'completed') {
635
- return fetchCompletedChallenges(brand, page, limit);
635
+ const completedIds = fetchCompletedChallenges(brand, page, limit);
636
+ return fetchAll(brand, type,
637
+ {
638
+ page,
639
+ limit,
640
+ searchTerm,
641
+ sort,
642
+ includedFields,
643
+ groupBy,
644
+ completedIds,
645
+ useDefaultFields,
646
+ customFields,
647
+ progress
648
+ });
636
649
  } else if (groupBy === 'owned') {
637
- return fetchOwnedChallenges(brand, page, limit);
650
+ const ownedIds = fetchOwnedChallenges(brand, page, limit);
651
+ return fetchAll(brand, type,
652
+ {
653
+ page,
654
+ limit,
655
+ searchTerm,
656
+ sort,
657
+ includedFields,
658
+ groupBy,
659
+ ownedIds,
660
+ useDefaultFields,
661
+ customFields,
662
+ progress
663
+ });
664
+ } else if (groupBy === 'difficulty_string') {
665
+ return fetchChallengesByDifficulty(brand, type, page, limit, searchTerm, sort, includedFields, groupBy, progressIds, useDefaultFields, customFields, progress);
638
666
  }
639
667
  }
640
668
  return null;
641
669
  }
642
670
 
671
+ async function fetchChallengesByDifficulty(brand, type, page, limit, searchTerm, sort, includedFields, groupBy, progressIds, useDefaultFields, customFields, progress) {
672
+ let config = contentTypeConfig['challenge'] ?? {};
673
+ let additionalFields = config?.fields ?? [];
674
+
675
+ // Construct the search filter
676
+ const searchFilter = searchTerm
677
+ ? groupBy !== "" ?
678
+ `&& (^.name match "${searchTerm}*" || title match "${searchTerm}*")`
679
+ : `&& (artist->name match "${searchTerm}*" || instructor[]->name match "${searchTerm}*" || title match "${searchTerm}*" || name match "${searchTerm}*")`
680
+ : "";
681
+
682
+ // Construct the included fields filter, replacing 'difficulty' with 'difficulty_string'
683
+ const includedFieldsFilter = includedFields.length > 0
684
+ ? filtersToGroq(includedFields)
685
+ : "";
686
+
687
+ // limits the results to supplied progressIds for started & completed filters
688
+ const progressFilter = await getProgressFilter(progress, progressIds);
689
+
690
+ let fields = useDefaultFields ? customFields.concat(DEFAULT_FIELDS, additionalFields) : customFields;
691
+ let fieldsString = fields.join(',');
692
+
693
+
694
+ const lessonsFilter = `_type == 'challenge' && brand == '${brand}' && ^.name == difficulty_string ${searchFilter} ${includedFieldsFilter} ${progressFilter}`;
695
+ const lessonsFilterWithRestrictions = await new FilterBuilder(lessonsFilter).buildFilter();
696
+
697
+ const query = `{
698
+ "entity": [
699
+ {"name": "All"},
700
+ {"name": "Novice"},
701
+ {"name": "Beginner"},
702
+ {"name": "Intermediate"},
703
+ {"name": "Advanced"},
704
+ {"name": "Expert"}]
705
+ {
706
+ 'id': 0,
707
+ name,
708
+ 'all_lessons_count': count(*[${lessonsFilterWithRestrictions}]._id),
709
+ 'lessons': *[${lessonsFilterWithRestrictions}]{
710
+ ${fieldsString},
711
+ name
712
+ }[0...20]
713
+ },
714
+ "total": 0
715
+ }`;
716
+ let data = await fetchSanity(query, true);
717
+ data.entity = data.entity.filter(function (difficulty) {
718
+ return difficulty.lessons.length > 0;
719
+ });
720
+ return data;
721
+ }
722
+
643
723
  async function getProgressFilter(progress, progressIds) {
644
724
  switch (progress) {
645
725
  case "all":
File without changes
File without changes
File without changes
File without changes
File without changes
package/test/log.js CHANGED
File without changes
@@ -256,6 +256,26 @@ 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
+
272
+ test('fetchAllChallengesByDifficulty', async () => {
273
+ const response = await fetchAll('drumeo', 'challenge', {groupBy:'difficulty_string'});
274
+ expect(response.entity[0].name).toBeDefined();
275
+ expect(response.entity[0].lessons).toBeDefined();
276
+ expect(response.entity[0].lessons.length).toBeGreaterThan(0)
277
+ });
278
+
259
279
  test('fetchAll-CustomFields', async () => {
260
280
  let response = await fetchAll('drumeo', 'challenge', {customFields: ['garbage']});
261
281
  log(response);
File without changes
File without changes