musora-content-services 2.28.3 → 2.28.5
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 +9 -0
- package/docs/ContentOrganization.html +2 -2
- package/docs/Gamification.html +2 -2
- package/docs/UserManagementSystem.html +2 -2
- package/docs/api_types.js.html +2 -2
- package/docs/config.js.html +2 -2
- package/docs/content-org_content-org.js.html +2 -2
- package/docs/content-org_playlists-types.js.html +2 -2
- package/docs/content-org_playlists.js.html +2 -2
- package/docs/content.js.html +4 -4
- package/docs/gamification_awards.js.html +2 -2
- package/docs/gamification_gamification.js.html +2 -2
- package/docs/gamification_types.js.html +2 -2
- package/docs/global.html +2 -2
- package/docs/index.html +2 -2
- package/docs/module-Awards.html +2 -2
- package/docs/module-Config.html +2 -2
- package/docs/module-Content-Services-V2.html +4 -4
- package/docs/module-Interests.html +2 -2
- package/docs/module-Permissions.html +2 -2
- package/docs/module-Playlists.html +2 -2
- package/docs/module-Railcontent-Services.html +590 -2987
- package/docs/module-Sanity-Services.html +30 -664
- package/docs/module-Sessions.html +2 -2
- package/docs/module-UserActivity.html +21 -21
- package/docs/module-UserChat.html +2 -2
- package/docs/module-UserManagement.html +2 -2
- package/docs/module-UserNotifications.html +2 -2
- package/docs/module-UserProfile.html +2 -2
- package/docs/railcontent.js.html +2 -196
- package/docs/sanity.js.html +17 -209
- package/docs/userActivity.js.html +4 -3
- package/docs/user_chat.js.html +2 -2
- package/docs/user_interests.js.html +2 -2
- package/docs/user_management.js.html +2 -2
- package/docs/user_notifications.js.html +2 -2
- package/docs/user_permissions.js.html +2 -2
- package/docs/user_profile.js.html +2 -2
- package/docs/user_sessions.js.html +2 -2
- package/docs/user_types.js.html +2 -2
- package/docs/user_user-management-system.js.html +2 -2
- package/package.json +1 -1
- package/src/contentMetaData.js +0 -24
- package/src/contentTypeConfig.js +2 -41
- package/src/index.d.ts +0 -30
- package/src/index.js +1 -31
- package/src/services/content.js +2 -2
- package/src/services/railcontent.js +0 -194
- package/src/services/sanity.js +13 -173
- package/src/services/userActivity.js +0 -1
- package/test/live/railcontentLive.test.js +0 -7
- package/test/sanityQueryService.test.js +3 -55
- package/docs/Content-Organization.html +0 -245
- package/docs/UserManagement.html +0 -269
- package/docs/global.html#User +0 -293
- package/docs/module-Notifications.html +0 -1183
- package/docs/module-Session-Management.html +0 -575
- package/docs/module-User-Activity.html +0 -4410
- package/docs/module-User-Management.html +0 -490
- package/docs/module-User-Permissions.html +0 -406
- package/docs/types.js.html +0 -122
- package/docs/user_user-management.js.html +0 -78
|
@@ -21,8 +21,6 @@ const excludeFromGeneratedIndex = [
|
|
|
21
21
|
'fetchUserPermissionsData',
|
|
22
22
|
]
|
|
23
23
|
|
|
24
|
-
let challengeIndexMetaDataPromise = null
|
|
25
|
-
|
|
26
24
|
/**
|
|
27
25
|
* Fetches the completion status of a specific lesson for the current user.
|
|
28
26
|
*
|
|
@@ -347,67 +345,6 @@ export async function postRecordWatchSession(
|
|
|
347
345
|
})
|
|
348
346
|
}
|
|
349
347
|
|
|
350
|
-
/**
|
|
351
|
-
* Fetch enrolled user data for a given challenge. Intended to be used in the enrolled modal
|
|
352
|
-
*
|
|
353
|
-
* @param contentId - railcontent id of the challenge
|
|
354
|
-
* @returns {Promise<any|null>}
|
|
355
|
-
*/
|
|
356
|
-
export async function fetchChallengeMetadata(contentId) {
|
|
357
|
-
let url = `/challenges/${contentId}`
|
|
358
|
-
return await fetchHandler(url, 'get')
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Fetch lesson, user, and challenge data for a given lesson
|
|
363
|
-
*
|
|
364
|
-
* @param contentId - railcontent id of the lesson
|
|
365
|
-
* @returns {Promise<any|null>}
|
|
366
|
-
*/
|
|
367
|
-
export async function fetchChallengeLessonData(contentId) {
|
|
368
|
-
let url = `/challenges/lessons/${contentId}`
|
|
369
|
-
return await fetchHandler(url, 'get')
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Fetch all owned brand challenges for user
|
|
374
|
-
* @param {string|null} brand - brand
|
|
375
|
-
* @param {int} page - page of data to pull
|
|
376
|
-
* @param {int} limit - number of elements to pull
|
|
377
|
-
* @returns {Promise<any|null>}
|
|
378
|
-
*/
|
|
379
|
-
export async function fetchOwnedChallenges(brand = null, page, limit) {
|
|
380
|
-
let brandParam = brand ? `&brand=${brand}` : ''
|
|
381
|
-
let pageAndLimit = `?page=${page}&limit=${limit}`
|
|
382
|
-
let url = `/challenges/tab_owned/get${pageAndLimit}${brandParam}`
|
|
383
|
-
return await fetchHandler(url, 'get')
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Fetch all completed brand challenges for user
|
|
388
|
-
* @param {string|null} brand - brand
|
|
389
|
-
* @param {int} page - page of data to pull
|
|
390
|
-
* @param {int} limit - number of elements to pull
|
|
391
|
-
* @returns {Promise<any|null>}
|
|
392
|
-
*/
|
|
393
|
-
export async function fetchCompletedChallenges(brand = null, page, limit) {
|
|
394
|
-
let brandParam = brand ? `&brand=${brand}` : ''
|
|
395
|
-
let pageAndLimit = `?page=${page}&limit=${limit}`
|
|
396
|
-
let url = `/challenges/tab_completed/get${pageAndLimit}${brandParam}`
|
|
397
|
-
return await fetchHandler(url, 'get')
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Fetch challenge, lesson, and user metadata for a given challenge
|
|
402
|
-
*
|
|
403
|
-
* @param contentId - railcontent id of the challenge
|
|
404
|
-
* @returns {Promise<any|null>}
|
|
405
|
-
*/
|
|
406
|
-
export async function fetchUserChallengeProgress(contentId) {
|
|
407
|
-
let url = `/challenges/user_data/${contentId}`
|
|
408
|
-
return await fetchHandler(url, 'get')
|
|
409
|
-
}
|
|
410
|
-
|
|
411
348
|
/**
|
|
412
349
|
* Fetch the user's best award for this challenge
|
|
413
350
|
*
|
|
@@ -419,44 +356,6 @@ export async function fetchUserAward(contentId) {
|
|
|
419
356
|
return await fetchHandler(url, 'get')
|
|
420
357
|
}
|
|
421
358
|
|
|
422
|
-
/**
|
|
423
|
-
* Get challenge duration, user progress, and status for the list of challenges
|
|
424
|
-
* Intended to be used on the index page for challenges
|
|
425
|
-
*
|
|
426
|
-
* @param {array} contentIds - arary of railcontent ids of the challenges
|
|
427
|
-
* @returns {Promise<any|null>}
|
|
428
|
-
*/
|
|
429
|
-
export async function fetchChallengeIndexMetadata(contentIds) {
|
|
430
|
-
if (!challengeIndexMetaDataPromise) {
|
|
431
|
-
challengeIndexMetaDataPromise = getChallengeIndexMetadataPromise()
|
|
432
|
-
}
|
|
433
|
-
let results = await challengeIndexMetaDataPromise
|
|
434
|
-
if (Array.isArray(contentIds)) {
|
|
435
|
-
results = results.filter(function (challenge) {
|
|
436
|
-
return contentIds.includes(challenge.content_id)
|
|
437
|
-
})
|
|
438
|
-
}
|
|
439
|
-
return results
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
async function getChallengeIndexMetadataPromise() {
|
|
443
|
-
let url = `/challenges/user_progress_for_index_page/get`
|
|
444
|
-
const result = await fetchHandler(url, 'get')
|
|
445
|
-
challengeIndexMetaDataPromise = null
|
|
446
|
-
return result
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Get active brand challenges for the authorized user
|
|
451
|
-
*
|
|
452
|
-
* @returns {Promise<any|null>}
|
|
453
|
-
*/
|
|
454
|
-
export async function fetchChallengeUserActiveChallenges(brand = null) {
|
|
455
|
-
let brandParam = brand ? `?brand=${brand}` : ''
|
|
456
|
-
let url = `/challenges/user_active_challenges/get${brandParam}`
|
|
457
|
-
return await fetchHandler(url, 'get')
|
|
458
|
-
}
|
|
459
|
-
|
|
460
359
|
/**
|
|
461
360
|
* Fetch All Carousel Card Data
|
|
462
361
|
*
|
|
@@ -480,99 +379,6 @@ export async function fetchUserBadges(brand = null) {
|
|
|
480
379
|
return await fetchHandler(url, 'get')
|
|
481
380
|
}
|
|
482
381
|
|
|
483
|
-
/**
|
|
484
|
-
* Enroll a user in a challenge and set the start date of the challenge to the provided day.
|
|
485
|
-
* Clears any existing progress data for this challenge
|
|
486
|
-
*
|
|
487
|
-
* @param {int|string} contentId - railcontent id of the challenge
|
|
488
|
-
* @param {string} startDate - prefered format YYYYMMDD, but any Carbon parsable string will do.
|
|
489
|
-
* @returns {Promise<any|null>}
|
|
490
|
-
*/
|
|
491
|
-
export async function postChallengesSetStartDate(contentId, startDate) {
|
|
492
|
-
let url = `/challenges/set_start_date/${contentId}?start_date=${startDate}`
|
|
493
|
-
return await fetchHandler(url, 'post')
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Enroll the user in the provided challenge and set to unlocked
|
|
498
|
-
* Clears any current progress data for this challenge
|
|
499
|
-
*
|
|
500
|
-
* @param {int|string} contentId - railcontent id of the challenge
|
|
501
|
-
* @returns {Promise<any|null>}
|
|
502
|
-
*/
|
|
503
|
-
export async function postChallengesUnlock(contentId) {
|
|
504
|
-
let url = `/challenges/unlock/${contentId}`
|
|
505
|
-
return await fetchHandler(url, 'post')
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* Enroll the user in the given challenge on the challenge published_on date
|
|
510
|
-
* Clears any current progress data for this challenge
|
|
511
|
-
*
|
|
512
|
-
* @param {int|string} contentId - railcontent id of the challenge
|
|
513
|
-
* @returns {Promise<any|null>}
|
|
514
|
-
*/
|
|
515
|
-
export async function postChallengesEnroll(contentId) {
|
|
516
|
-
let url = `/challenges/enroll/${contentId}`
|
|
517
|
-
return await fetchHandler(url, 'post')
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* Remove the user from the provided challenge
|
|
522
|
-
* Clears any current progress data for this challenge
|
|
523
|
-
*
|
|
524
|
-
* @param {int|string} contentId - railcontent id of the challenge
|
|
525
|
-
* @returns {Promise<any|null>}
|
|
526
|
-
*/
|
|
527
|
-
export async function postChallengesLeave(contentId) {
|
|
528
|
-
let url = `/challenges/leave/${contentId}`
|
|
529
|
-
return await fetchHandler(url, 'post')
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Enable enrollment notifications for the provided challenge
|
|
534
|
-
*
|
|
535
|
-
* @param {int|string} contentId - railcontent id of the challenge
|
|
536
|
-
* @returns {Promise<any|null>}
|
|
537
|
-
*/
|
|
538
|
-
export async function postChallengesEnrollmentNotification(contentId) {
|
|
539
|
-
let url = `/challenges/notifications/enrollment_open/${contentId}`
|
|
540
|
-
return await fetchHandler(url, 'post')
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* Enable community notifications for the provided challenge
|
|
545
|
-
*
|
|
546
|
-
* @param {int|string} contentId - railcontent id of the challenge
|
|
547
|
-
* @returns {Promise<any|null>}
|
|
548
|
-
*/
|
|
549
|
-
export async function postChallengesCommunityNotification(contentId) {
|
|
550
|
-
let url = `/challenges/notifications/community_reminders/${contentId}`
|
|
551
|
-
return await fetchHandler(url, 'post')
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* Enable solo notifications for the provided challenge
|
|
556
|
-
*
|
|
557
|
-
* @param {int|string} contentId - railcontent id of the challenge
|
|
558
|
-
* @returns {Promise<any|null>}
|
|
559
|
-
*/
|
|
560
|
-
export async function postChallengesSoloNotification(contentId) {
|
|
561
|
-
let url = `/challenges/notifications/solo_reminders/${contentId}`
|
|
562
|
-
return await fetchHandler(url, 'post')
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Hide challenge completed award bannare
|
|
567
|
-
*
|
|
568
|
-
* @param {int|string} contentId - railcontent id of the challenge
|
|
569
|
-
* @returns {Promise<any|null>}
|
|
570
|
-
*/
|
|
571
|
-
export async function postChallengesHideCompletedBanner(contentId) {
|
|
572
|
-
let url = `/challenges/hide_completed_banner/${contentId}`
|
|
573
|
-
return await fetchHandler(url, 'post')
|
|
574
|
-
}
|
|
575
|
-
|
|
576
382
|
export async function postContentComplete(contentId) {
|
|
577
383
|
let url = `/api/content/v1/user/progress/complete/${contentId}`
|
|
578
384
|
return postDataHandler(url)
|
package/src/services/sanity.js
CHANGED
|
@@ -25,8 +25,6 @@ import { processMetadata, typeWithSortOrder } from '../contentMetaData.js'
|
|
|
25
25
|
import { globalConfig } from './config.js'
|
|
26
26
|
|
|
27
27
|
import {
|
|
28
|
-
fetchCompletedChallenges,
|
|
29
|
-
fetchOwnedChallenges,
|
|
30
28
|
fetchNextContentDataForParent,
|
|
31
29
|
fetchHandler,
|
|
32
30
|
} from './railcontent.js'
|
|
@@ -40,7 +38,7 @@ import {fetchRecentActivitiesActiveTabs} from "./userActivity.js";
|
|
|
40
38
|
*
|
|
41
39
|
* @type {string[]}
|
|
42
40
|
*/
|
|
43
|
-
const excludeFromGeneratedIndex = ['
|
|
41
|
+
const excludeFromGeneratedIndex = ['fetchRelatedByLicense']
|
|
44
42
|
|
|
45
43
|
/**
|
|
46
44
|
* Fetch a song by its document ID from Sanity.
|
|
@@ -567,15 +565,17 @@ export async function fetchContentRows(brand, pageName, contentRowSlug)
|
|
|
567
565
|
if (pageName === 'lessons') pageName = 'lesson'
|
|
568
566
|
if (pageName === 'songs') pageName = 'song'
|
|
569
567
|
const rowString = contentRowSlug ? ` && slug.current == "${contentRowSlug.toLowerCase()}"` : ''
|
|
570
|
-
|
|
568
|
+
const childFilter = await new FilterBuilder('', {isChildrenFilter: true}).buildFilter()
|
|
569
|
+
const query = `*[_type == 'recommended-content-row' && brand == '${brand}' && type == '${pageName}'${rowString}]{
|
|
571
570
|
brand,
|
|
572
571
|
name,
|
|
573
572
|
'slug': slug.current,
|
|
574
|
-
'content': content[]->{
|
|
575
|
-
'children': child[]->{ 'id': railcontent_id, 'children': child[]->{'id': railcontent_id}, },
|
|
573
|
+
'content': content[${childFilter}]->{
|
|
574
|
+
'children': child[${childFilter}]->{ 'id': railcontent_id, 'children': child[${childFilter}]->{'id': railcontent_id}, },
|
|
576
575
|
${getFieldsForContentType('tab-data')}
|
|
577
576
|
},
|
|
578
|
-
}
|
|
577
|
+
}`
|
|
578
|
+
return fetchSanity(query, true)
|
|
579
579
|
}
|
|
580
580
|
|
|
581
581
|
|
|
@@ -628,21 +628,6 @@ export async function fetchAll(
|
|
|
628
628
|
progress = 'all',
|
|
629
629
|
} = {}
|
|
630
630
|
) {
|
|
631
|
-
let customResults = await handleCustomFetchAll(brand, type, {
|
|
632
|
-
page,
|
|
633
|
-
limit,
|
|
634
|
-
searchTerm,
|
|
635
|
-
sort,
|
|
636
|
-
includedFields,
|
|
637
|
-
groupBy,
|
|
638
|
-
progressIds,
|
|
639
|
-
useDefaultFields,
|
|
640
|
-
customFields,
|
|
641
|
-
progress,
|
|
642
|
-
})
|
|
643
|
-
if (customResults) {
|
|
644
|
-
return customResults
|
|
645
|
-
}
|
|
646
631
|
let config = contentTypeConfig[type] ?? {}
|
|
647
632
|
let additionalFields = config?.fields ?? []
|
|
648
633
|
let isGroupByOneToOne = (groupBy ? config?.relationships?.[groupBy]?.isOneToOne : false) ?? false
|
|
@@ -665,9 +650,7 @@ export async function fetchAll(
|
|
|
665
650
|
} else {
|
|
666
651
|
typeFilter = type
|
|
667
652
|
? `&& _type == '${type}'`
|
|
668
|
-
:
|
|
669
|
-
? " && (_type != 'challenge-part' && _type != 'challenge')"
|
|
670
|
-
: ''
|
|
653
|
+
: ''
|
|
671
654
|
}
|
|
672
655
|
|
|
673
656
|
// Construct the search filter
|
|
@@ -765,152 +748,6 @@ export async function fetchAll(
|
|
|
765
748
|
return fetchSanity(query, true)
|
|
766
749
|
}
|
|
767
750
|
|
|
768
|
-
/**
|
|
769
|
-
* Fetch all content that requires custom handling or a distinct external call
|
|
770
|
-
* @param {string} brand - The brand for which to fetch content.
|
|
771
|
-
* @param {string} type - The content type to fetch (e.g., 'song', 'artist').
|
|
772
|
-
* @param {Object} params - Parameters for pagination, filtering, sorting, and grouping.
|
|
773
|
-
* @param {number} [params.page=1] - The page number for pagination.
|
|
774
|
-
* @param {number} [params.limit=10] - The number of items per page.
|
|
775
|
-
* @param {string} [params.searchTerm=""] - The search term to filter content by title or artist.
|
|
776
|
-
* @param {string} [params.sort="-published_on"] - The field to sort the content by.
|
|
777
|
-
* @param {Array<string>} [params.includedFields=[]] - The fields to include in the query.
|
|
778
|
-
* @param {string} [params.groupBy=""] - The field to group the results by (e.g., 'artist', 'genre').
|
|
779
|
-
* @param {Array<string>} [params.progressIds=undefined] - An array of railcontent IDs to filter the results by. Used for filtering by progress.
|
|
780
|
-
* @param {boolean} [params.useDefaultFields=true] - use the default sanity fields for content Type
|
|
781
|
-
* @param {Array<string>} [params.customFields=[]] - An array of sanity fields to include in the request
|
|
782
|
-
* @param {string} [params.progress="all"] - An string representing which progress filter to use ("all", "in progress", "complete", "not started").
|
|
783
|
-
* @returns {Promise<Object|null>} - The fetched content data or null if not found.
|
|
784
|
-
*/
|
|
785
|
-
async function handleCustomFetchAll(
|
|
786
|
-
brand,
|
|
787
|
-
type,
|
|
788
|
-
{
|
|
789
|
-
page = 1,
|
|
790
|
-
limit = 10,
|
|
791
|
-
searchTerm = '',
|
|
792
|
-
sort = '-published_on',
|
|
793
|
-
includedFields = [],
|
|
794
|
-
groupBy = '',
|
|
795
|
-
progressIds = undefined,
|
|
796
|
-
useDefaultFields = true,
|
|
797
|
-
customFields = [],
|
|
798
|
-
progress = 'all',
|
|
799
|
-
} = {}
|
|
800
|
-
) {
|
|
801
|
-
if (type === 'challenge') {
|
|
802
|
-
if (groupBy === 'completed') {
|
|
803
|
-
const completedIds = await fetchCompletedChallenges(brand, page, limit)
|
|
804
|
-
return fetchAll(brand, type, {
|
|
805
|
-
page,
|
|
806
|
-
limit,
|
|
807
|
-
searchTerm,
|
|
808
|
-
sort,
|
|
809
|
-
includedFields,
|
|
810
|
-
groupBy: '',
|
|
811
|
-
progressIds: completedIds,
|
|
812
|
-
useDefaultFields,
|
|
813
|
-
customFields,
|
|
814
|
-
progress,
|
|
815
|
-
})
|
|
816
|
-
} else if (groupBy === 'owned') {
|
|
817
|
-
const ownedIds = await fetchOwnedChallenges(brand, page, limit)
|
|
818
|
-
return fetchAll(brand, type, {
|
|
819
|
-
page,
|
|
820
|
-
limit,
|
|
821
|
-
searchTerm,
|
|
822
|
-
sort,
|
|
823
|
-
includedFields,
|
|
824
|
-
groupBy: '',
|
|
825
|
-
progressIds: ownedIds,
|
|
826
|
-
useDefaultFields,
|
|
827
|
-
customFields,
|
|
828
|
-
progress,
|
|
829
|
-
})
|
|
830
|
-
} else if (groupBy === 'difficulty_string') {
|
|
831
|
-
return fetchChallengesByDifficulty(
|
|
832
|
-
brand,
|
|
833
|
-
type,
|
|
834
|
-
page,
|
|
835
|
-
limit,
|
|
836
|
-
searchTerm,
|
|
837
|
-
sort,
|
|
838
|
-
includedFields,
|
|
839
|
-
groupBy,
|
|
840
|
-
progressIds,
|
|
841
|
-
useDefaultFields,
|
|
842
|
-
customFields,
|
|
843
|
-
progress
|
|
844
|
-
)
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
return null
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
async function fetchChallengesByDifficulty(
|
|
851
|
-
brand,
|
|
852
|
-
type,
|
|
853
|
-
page,
|
|
854
|
-
limit,
|
|
855
|
-
searchTerm,
|
|
856
|
-
sort,
|
|
857
|
-
includedFields,
|
|
858
|
-
groupBy,
|
|
859
|
-
progressIds,
|
|
860
|
-
useDefaultFields,
|
|
861
|
-
customFields,
|
|
862
|
-
progress
|
|
863
|
-
) {
|
|
864
|
-
let config = contentTypeConfig['challenge'] ?? {}
|
|
865
|
-
let additionalFields = config?.fields ?? []
|
|
866
|
-
|
|
867
|
-
// Construct the search filter
|
|
868
|
-
const searchFilter = searchTerm
|
|
869
|
-
? groupBy !== ''
|
|
870
|
-
? `&& (^.name match "${searchTerm}*" || title match "${searchTerm}*")`
|
|
871
|
-
: `&& (artist->name match "${searchTerm}*" || instructor[]->name match "${searchTerm}*" || title match "${searchTerm}*" || name match "${searchTerm}*")`
|
|
872
|
-
: ''
|
|
873
|
-
|
|
874
|
-
// Construct the included fields filter, replacing 'difficulty' with 'difficulty_string'
|
|
875
|
-
const includedFieldsFilter = includedFields.length > 0 ? filtersToGroq(includedFields) : ''
|
|
876
|
-
|
|
877
|
-
// limits the results to supplied progressIds for started & completed filters
|
|
878
|
-
const progressFilter = await getProgressFilter(progress, progressIds)
|
|
879
|
-
|
|
880
|
-
let fields = useDefaultFields
|
|
881
|
-
? customFields.concat(DEFAULT_FIELDS, additionalFields)
|
|
882
|
-
: customFields
|
|
883
|
-
let fieldsString = fields.join(',')
|
|
884
|
-
|
|
885
|
-
const lessonsFilter = `_type == 'challenge' && brand == '${brand}' && ^.name == difficulty_string ${searchFilter} ${includedFieldsFilter} ${progressFilter}`
|
|
886
|
-
const lessonsFilterWithRestrictions = await new FilterBuilder(lessonsFilter).buildFilter()
|
|
887
|
-
|
|
888
|
-
const query = `{
|
|
889
|
-
"entity": [
|
|
890
|
-
{"name": "All"},
|
|
891
|
-
{"name": "Novice"},
|
|
892
|
-
{"name": "Beginner"},
|
|
893
|
-
{"name": "Intermediate"},
|
|
894
|
-
{"name": "Advanced"},
|
|
895
|
-
{"name": "Expert"}]
|
|
896
|
-
{
|
|
897
|
-
'id': 0,
|
|
898
|
-
name,
|
|
899
|
-
'all_lessons_count': count(*[${lessonsFilterWithRestrictions}]._id),
|
|
900
|
-
'lessons': *[${lessonsFilterWithRestrictions}]{
|
|
901
|
-
${fieldsString},
|
|
902
|
-
name
|
|
903
|
-
}[0...20]
|
|
904
|
-
},
|
|
905
|
-
"total": 0
|
|
906
|
-
}`
|
|
907
|
-
let data = await fetchSanity(query, true)
|
|
908
|
-
data.entity = data.entity.filter(function (difficulty) {
|
|
909
|
-
return difficulty.lessons.length > 0
|
|
910
|
-
})
|
|
911
|
-
return data
|
|
912
|
-
}
|
|
913
|
-
|
|
914
751
|
async function getProgressFilter(progress, progressIds) {
|
|
915
752
|
switch (progress) {
|
|
916
753
|
case 'all':
|
|
@@ -1430,7 +1267,7 @@ async function fetchRelatedByLicense(railcontentId, brand, onlyUseSongTypes, cou
|
|
|
1430
1267
|
*[${filterSongTypesWithSameLicense}]->{${queryFields}}|order(published_on desc, title asc)[0...${count}],
|
|
1431
1268
|
}[0...1]`
|
|
1432
1269
|
const results = await fetchSanity(query, false)
|
|
1433
|
-
return results['related_by_license'] ?? []
|
|
1270
|
+
return results ? results['related_by_license'] ?? [] : []
|
|
1434
1271
|
}
|
|
1435
1272
|
|
|
1436
1273
|
/**
|
|
@@ -1632,7 +1469,7 @@ export async function fetchLiveEvent(brand, forcedContentId = null) {
|
|
|
1632
1469
|
*
|
|
1633
1470
|
* @example
|
|
1634
1471
|
* fetchPackData(404048)
|
|
1635
|
-
* .then(
|
|
1472
|
+
* .then(pack => console.log(pack))
|
|
1636
1473
|
* .catch(error => console.error(error));
|
|
1637
1474
|
*/
|
|
1638
1475
|
export async function fetchPackData(id) {
|
|
@@ -2027,6 +1864,9 @@ export async function fetchSanity(
|
|
|
2027
1864
|
console.log('fetchSanity Results:', result)
|
|
2028
1865
|
}
|
|
2029
1866
|
let results = isList ? result.result : result.result[0]
|
|
1867
|
+
if (!results) {
|
|
1868
|
+
throw new Error('No results found')
|
|
1869
|
+
}
|
|
2030
1870
|
results = processNeedAccess
|
|
2031
1871
|
? await needsAccessDecorator(results, userPermissions, isAdmin)
|
|
2032
1872
|
: results
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { initializeTestService } from '../initializeTests'
|
|
2
|
-
import { fetchChallengeIndexMetadata } from '../../src'
|
|
3
2
|
|
|
4
3
|
describe('railcontentLive', function () {
|
|
5
4
|
beforeEach(async () => {
|
|
6
5
|
await initializeTestService(true)
|
|
7
6
|
}, 1000000)
|
|
8
|
-
|
|
9
|
-
test('challengeIndexMetadata', async () => {
|
|
10
|
-
let contentId = 281709
|
|
11
|
-
let results = await fetchChallengeIndexMetadata([contentId])
|
|
12
|
-
expect(Array.isArray(results)).toBe(true)
|
|
13
|
-
})
|
|
14
7
|
})
|
|
@@ -5,7 +5,7 @@ const railContentModule = require('../src/services/railcontent.js')
|
|
|
5
5
|
import { log } from './log.js'
|
|
6
6
|
import { initializeTestService } from './initializeTests'
|
|
7
7
|
import { dataContext } from '../src/services/contentProgress'
|
|
8
|
-
import {
|
|
8
|
+
import { getRecommendedForYou, globalConfig, recommendations } from '../src'
|
|
9
9
|
import { fetchLessonsFeaturingThisContent } from '../src/services/sanity.js'
|
|
10
10
|
|
|
11
11
|
const {
|
|
@@ -15,13 +15,11 @@ const {
|
|
|
15
15
|
fetchLeaving,
|
|
16
16
|
fetchComingSoon,
|
|
17
17
|
fetchSongArtistCount,
|
|
18
|
-
fetchRelatedSongs,
|
|
19
18
|
fetchNewReleases,
|
|
20
19
|
fetchUpcomingEvents,
|
|
21
20
|
fetchByRailContentId,
|
|
22
21
|
fetchByRailContentIds,
|
|
23
22
|
fetchAll,
|
|
24
|
-
fetchAllOld,
|
|
25
23
|
fetchAllFilterOptions,
|
|
26
24
|
fetchFoundation,
|
|
27
25
|
fetchMethod,
|
|
@@ -224,53 +222,13 @@ describe('Sanity Queries', function() {
|
|
|
224
222
|
expect(response.entity[0].sort).toBeDefined()
|
|
225
223
|
})
|
|
226
224
|
|
|
227
|
-
test('fetchAllChallenges', async () => {
|
|
228
|
-
const response = await fetchAll('drumeo', 'challenge', {})
|
|
229
|
-
log(response)
|
|
230
|
-
expect(response.entity[0].registration_url).toBeDefined()
|
|
231
|
-
expect(response.entity[0].enrollment_start_time).toBeDefined()
|
|
232
|
-
expect(response.entity[0].enrollment_end_time).toBeDefined()
|
|
233
|
-
|
|
234
|
-
expect(response.entity[0].lesson_count).toBeDefined()
|
|
235
|
-
expect(response.entity[0].primary_cta_text).toBeDefined()
|
|
236
|
-
expect(response.entity[0].challenge_state).toBeDefined()
|
|
237
|
-
expect(response.entity[0].challenge_state_text).toBeDefined()
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
test('fetchAllChallengesByGenre', async () => {
|
|
241
|
-
const response = await fetchAll('drumeo', 'challenge', { groupBy: 'genre' })
|
|
242
|
-
expect(response.entity[0].type).toBe('genre')
|
|
243
|
-
expect(response.entity[0].lessons).toBeDefined()
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
test('fetchAllChallengesByDifficulty', async () => {
|
|
247
|
-
const response = await fetchAll('drumeo', 'challenge', { groupBy: 'difficulty_string' })
|
|
248
|
-
expect(response.entity[0].name).toBeDefined()
|
|
249
|
-
expect(response.entity[0].lessons).toBeDefined()
|
|
250
|
-
expect(response.entity[0].lessons.length).toBeGreaterThan(0)
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
test('fetchAllChallengesByCompleted', async () => {
|
|
254
|
-
var mock = jest.spyOn(railContentModule, 'fetchCompletedChallenges')
|
|
255
|
-
mock.mockImplementation(() => [402204])
|
|
256
|
-
const response = await fetchAll('drumeo', 'challenge', { groupBy: 'completed' })
|
|
257
|
-
expect(response.entity.length).toBe(1)
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
test('fetchAllChallengesByOwned', async () => {
|
|
261
|
-
var mock = jest.spyOn(railContentModule, 'fetchOwnedChallenges')
|
|
262
|
-
mock.mockImplementation(() => [402204])
|
|
263
|
-
const response = await fetchAll('drumeo', 'challenge', { groupBy: 'owned' })
|
|
264
|
-
expect(response.entity.length).toBe(1)
|
|
265
|
-
})
|
|
266
|
-
|
|
267
225
|
test('fetchAll-CustomFields', async () => {
|
|
268
|
-
let response = await fetchAll('drumeo', '
|
|
226
|
+
let response = await fetchAll('drumeo', 'course', { customFields: ['garbage'] })
|
|
269
227
|
log(response)
|
|
270
228
|
expect(response.entity[0].garbage).toBeDefined()
|
|
271
229
|
expect(response.entity[0].id).toBeDefined()
|
|
272
230
|
|
|
273
|
-
response = await fetchAll('drumeo', '
|
|
231
|
+
response = await fetchAll('drumeo', 'course', {
|
|
274
232
|
useDefaultFields: false, customFields: ['garbage'],
|
|
275
233
|
})
|
|
276
234
|
log(response)
|
|
@@ -807,16 +765,6 @@ describe('MetaData', function() {
|
|
|
807
765
|
expect(metaData).toBeNull()
|
|
808
766
|
})
|
|
809
767
|
|
|
810
|
-
test('onlyCommon', async () => {
|
|
811
|
-
const guitareoMetaData = processMetadata('guitareo', 'challenge')
|
|
812
|
-
const drumeoMetaData = processMetadata('drumeo', 'challenge')
|
|
813
|
-
guitareoMetaData.url = ''
|
|
814
|
-
drumeoMetaData.url = ''
|
|
815
|
-
expect(guitareoMetaData).toStrictEqual(drumeoMetaData)
|
|
816
|
-
expect(guitareoMetaData.type).toBe('challenge')
|
|
817
|
-
expect(guitareoMetaData.name).toBe('Challenges')
|
|
818
|
-
})
|
|
819
|
-
|
|
820
768
|
test('withCommon', async () => {
|
|
821
769
|
const guitareoMetaData = processMetadata('guitareo', 'instructor')
|
|
822
770
|
const drumeoMetaData = processMetadata('drumeo', 'instructor')
|