musora-content-services 1.0.181 → 1.0.183

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.183](https://github.com/railroadmedia/musora-content-services/compare/v1.0.182...v1.0.183) (2024-11-25)
6
+
7
+ ### [1.0.182](https://github.com/railroadmedia/musora-content-services/compare/v1.0.181...v1.0.182) (2024-11-25)
8
+
5
9
  ### [1.0.181](https://github.com/railroadmedia/musora-content-services/compare/v1.0.180...v1.0.181) (2024-11-25)
6
10
 
7
11
  ### [1.0.180](https://github.com/railroadmedia/musora-content-services/compare/v1.0.179...v1.0.180) (2024-11-23)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.181",
3
+ "version": "1.0.183",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -347,7 +347,7 @@ let contentTypeConfig = {
347
347
  '"focus": focus[]->name',
348
348
  'focus_text',
349
349
  'forum_thread_id',
350
- '"long_bio": long_bio[0].children[0].text,',
350
+ '"long_bio": long_bio[0].children[0].text',
351
351
  'name',
352
352
  '"short_bio" : short_bio[0].children[0].text',
353
353
  'bands',
@@ -499,7 +499,8 @@ export async function fetchAll(brand, type, {
499
499
  progressIds,
500
500
  useDefaultFields,
501
501
  customFields,
502
- progress});
502
+ progress
503
+ });
503
504
  if (customResults) {
504
505
  return customResults;
505
506
  }
@@ -510,7 +511,7 @@ export async function fetchAll(brand, type, {
510
511
  let webUrlPathType = config?.slug ?? type;
511
512
  const start = (page - 1) * limit;
512
513
  const end = start + limit;
513
- let bypassStatusAndPublishedValidation = (type == 'instructor');
514
+ let bypassStatusAndPublishedValidation = (type == 'instructor' || groupBy == 'artist' || groupBy == 'genre' || groupBy == 'instructor');
514
515
 
515
516
  // Construct the type filter
516
517
  const typeFilter = type ? `&& _type == '${type}'` : "";
@@ -543,14 +544,15 @@ export async function fetchAll(brand, type, {
543
544
  if (groupBy !== "" && isGroupByOneToOne) {
544
545
  const webUrlPath = 'artists';
545
546
  const lessonsFilter = `_type == '${type}' && brand == '${brand}' && ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}`;
547
+ const lessonsFilterWithRestrictions = await new FilterBuilder(lessonsFilter).buildFilter();
546
548
  entityFieldsString = `
547
549
  'id': railcontent_id,
548
550
  'type': _type,
549
551
  name,
550
552
  'head_shot_picture_url': thumbnail_url.asset->url,
551
553
  'web_url_path': '/${brand}/${webUrlPath}/'+name+'?included_fieds[]=type,${type}',
552
- 'all_lessons_count': count(*[${lessonsFilter}]._id),
553
- 'lessons': *[${lessonsFilter}]{
554
+ 'all_lessons_count': count(*[${lessonsFilterWithRestrictions}]._id),
555
+ 'lessons': *[${lessonsFilterWithRestrictions}]{
554
556
  ${fieldsString},
555
557
  ${groupBy}
556
558
  }[0...20]
@@ -559,14 +561,16 @@ export async function fetchAll(brand, type, {
559
561
  } else if (groupBy !== "") {
560
562
  const webUrlPath = (groupBy == 'genre') ? '/genres' : '';
561
563
  const lessonsFilter = `brand == '${brand}' && ^._id in ${groupBy}[]._ref ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}`;
564
+ const lessonsFilterWithRestrictions = await new FilterBuilder(lessonsFilter).buildFilter();
565
+
562
566
  entityFieldsString = `
563
567
  'id': railcontent_id,
564
568
  'type': _type,
565
569
  name,
566
570
  'head_shot_picture_url': thumbnail_url.asset->url,
567
571
  'web_url_path': select(defined(web_url_path)=> web_url_path +'?included_fieds[]=type,${type}',!defined(web_url_path)=> '/${brand}${webUrlPath}/'+name+'/${webUrlPathType}'),
568
- 'all_lessons_count': count(*[${lessonsFilter}]._id),
569
- 'lessons': *[${lessonsFilter}]{
572
+ 'all_lessons_count': count(*[${lessonsFilterWithRestrictions}]._id),
573
+ 'lessons': *[${lessonsFilterWithRestrictions}]{
570
574
  ${fieldsString},
571
575
  ${groupBy}
572
576
  }[0...20]`;
@@ -576,7 +580,11 @@ export async function fetchAll(brand, type, {
576
580
  entityFieldsString = fieldsString;
577
581
  }
578
582
 
579
- const filterWithRestrictions = await new FilterBuilder(filter,{bypassStatuses:bypassStatusAndPublishedValidation, bypassPermissions: bypassStatusAndPublishedValidation, bypassPublishedDateRestriction: bypassStatusAndPublishedValidation} ).buildFilter();
583
+ const filterWithRestrictions = await new FilterBuilder(filter, {
584
+ bypassStatuses: bypassStatusAndPublishedValidation,
585
+ bypassPermissions: bypassStatusAndPublishedValidation,
586
+ bypassPublishedDateRestriction: bypassStatusAndPublishedValidation
587
+ }).buildFilter();
580
588
  query = buildEntityAndTotalQuery(
581
589
  filterWithRestrictions,
582
590
  entityFieldsString,
@@ -621,7 +629,7 @@ async function handleCustomFetchAll(brand, type, {
621
629
  if (type === 'challenge') {
622
630
  if (groupBy === 'completed') {
623
631
  return fetchCompletedChallenges(brand, page, limit);
624
- } else if(groupBy === 'owned') {
632
+ } else if (groupBy === 'owned') {
625
633
  return fetchOwnedChallenges(brand, page, limit);
626
634
  }
627
635
  }
@@ -906,7 +914,10 @@ export async function fetchMethodPreviousNextLesson(railcontentId, methodId) {
906
914
  const index = sortedChildren.indexOf(Number(railcontentId));
907
915
  let nextId = sortedChildren[index + 1];
908
916
  let previousId = sortedChildren[index - 1];
909
- let nextPrev = await fetchByRailContentIds([nextId, previousId]);
917
+ let ids = [];
918
+ if (nextId) ids.push(nextId);
919
+ if (previousId) ids.push(previousId);
920
+ let nextPrev = await fetchByRailContentIds(ids);
910
921
  const nextLesson = nextPrev.find((elem) => {
911
922
  return elem['id'] === nextId
912
923
  });
@@ -993,7 +1004,7 @@ export async function fetchNextPreviousLesson(railcontentId) {
993
1004
  * .catch(error => console.error(error));
994
1005
  */
995
1006
  export async function fetchLessonContent(railContentId) {
996
- const filterParams = {isSingle:true};
1007
+ const filterParams = {isSingle: true};
997
1008
  // Format changes made to the `fields` object may also need to be reflected in Musora-web-platform SanityGateway.php $fields object
998
1009
  // Currently only for challenges and challenge lessons
999
1010
  // If you're unsure, message Adrian, or just add them.
@@ -1,5 +1,10 @@
1
1
  import {getFieldsForContentType} from "../src/contentTypeConfig";
2
- import {fetchAssignments, fetchCommentModContentData, fetchSanity} from "../src/services/sanity";
2
+ import {
3
+ fetchAssignments,
4
+ fetchCommentModContentData,
5
+ fetchMethodPreviousNextLesson,
6
+ fetchSanity
7
+ } from "../src/services/sanity";
3
8
  import {log} from './log.js';
4
9
  import {initializeTestService} from "./initializeTests";
5
10
  import {dataContext} from "../src/services/contentProgress";
@@ -361,13 +366,13 @@ describe('Sanity Queries', function () {
361
366
  });
362
367
 
363
368
  test('fetchAll-WithProgress', async () => {
364
- const ids = [410213, 305649];
369
+ const ids = [410213, 410215];
365
370
  let response = await fetchAll('drumeo', 'song', {
366
371
  sort: 'slug',
367
372
  progressIds: ids,
368
373
  });
369
374
  expect(response.entity.length).toBe(2);
370
- expect(response.entity[0].id = 305649);
375
+ expect(response.entity[0].id = 410215);
371
376
  expect(response.entity[1].id = 410213);
372
377
  // change the type and we expect no results
373
378
  response = await fetchAll('drumeo', 'quick-tip', {
@@ -555,6 +560,17 @@ describe('Sanity Queries', function () {
555
560
  expect(response.nextLesson.sort).toBeGreaterThanOrEqual(document.sort);
556
561
  });
557
562
 
563
+ test('fetchMethodNextPreviousLesson-Last', async () => {
564
+ const id = 396234;
565
+ const methodId = 396229;
566
+ const response = await fetchMethodPreviousNextLesson(id, methodId);
567
+ log(response);
568
+ expect(response.prevLesson).toBeDefined();
569
+ expect(response.prevLesson.id).toBe(396233);
570
+ expect(response.prevLesson.type).toBe('course-part');
571
+ expect(response.nextLesson).not.toBeDefined();
572
+ });
573
+
558
574
  test('fetchNextPreviousLesson-Method-Lesson', async () => {
559
575
  const id = 241265;
560
576
  const response = await fetchNextPreviousLesson(id);