musora-content-services 1.0.189 → 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 CHANGED
@@ -2,6 +2,8 @@
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
+
5
7
  ### [1.0.189](https://github.com/railroadmedia/musora-content-services/compare/v1.0.188...v1.0.189) (2024-11-28)
6
8
 
7
9
  ### [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.190",
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
@@ -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":
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,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);
File without changes
File without changes