musora-content-services 1.0.59 → 1.0.62
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 +6 -0
- package/docs/config.js.html +2 -2
- package/docs/index.html +2 -2
- package/docs/module-Config.html +2 -2
- package/docs/module-Railcontent-Services.html +2 -2
- package/docs/module-Sanity-Services.html +851 -97
- package/docs/railcontent.js.html +2 -2
- package/docs/sanity.js.html +189 -150
- package/package.json +1 -1
- package/src/contentTypeConfig.js +71 -2
- package/src/index.d.ts +6 -2
- package/src/index.js +10 -2
- package/src/services/sanity.js +181 -141
- package/test/sanityQueryService.test.js +78 -13
package/docs/railcontent.js.html
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Config.html">Config</a><ul class='methods'><li data-type='method'><a href="module-Config.html#~initializeService">initializeService</a></li></ul></li><li><a href="module-Railcontent-Services.html">Railcontent-Services</a><ul class='methods'><li data-type='method'><a href="module-Railcontent-Services.html#.fetchAllCompletedStates">fetchAllCompletedStates</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentInProgress">fetchContentInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchCurrentSongComplete">fetchCurrentSongComplete</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</a></li></ul></li><li><a href="module-Sanity-Services.html">Sanity-Services</a><ul class='methods'><li data-type='method'><a href="module-Sanity-Services.html#.fetchAll">fetchAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllFilterOptions">fetchAllFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllSongs">fetchAllSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchArtists">fetchArtists</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentId">fetchByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentIds">fetchByRailContentIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchChildren">fetchChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCourseOverview">fetchCourseOverview</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchLessonContent">fetchLessonContent</a></li><li data-type='method'><a href="module-Sanity-Services.html#.
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Config.html">Config</a><ul class='methods'><li data-type='method'><a href="module-Config.html#~initializeService">initializeService</a></li></ul></li><li><a href="module-Railcontent-Services.html">Railcontent-Services</a><ul class='methods'><li data-type='method'><a href="module-Railcontent-Services.html#.fetchAllCompletedStates">fetchAllCompletedStates</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentInProgress">fetchContentInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchCurrentSongComplete">fetchCurrentSongComplete</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</a></li></ul></li><li><a href="module-Sanity-Services.html">Sanity-Services</a><ul class='methods'><li data-type='method'><a href="module-Sanity-Services.html#.fetchAll">fetchAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllFilterOptions">fetchAllFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllSongs">fetchAllSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchArtists">fetchArtists</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentId">fetchByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentIds">fetchByRailContentIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCatalogMetadata">fetchCatalogMetadata</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchChildren">fetchChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCourseOverview">fetchCourseOverview</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchLessonContent">fetchLessonContent</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethod">fetchMethod</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodChildrenIds">fetchMethodChildrenIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodNextLesson">fetchMethodNextLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodPreviousNextLesson">fetchMethodPreviousNextLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethods">fetchMethods</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchNewReleases">fetchNewReleases</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchNextPreviousLesson">fetchNextPreviousLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchPackAll">fetchPackAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchPackChildren">fetchPackChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchParentByRailContentId">fetchParentByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchRelatedLessons">fetchRelatedLessons</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchRelatedSongs">fetchRelatedSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSanity">fetchSanity</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongArtistCount">fetchSongArtistCount</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongById">fetchSongById</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongCount">fetchSongCount</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongFilterOptions">fetchSongFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchUpcomingEvents">fetchUpcomingEvents</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchWorkouts">fetchWorkouts</a></li></ul></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -201,7 +201,7 @@ export async function fetchContentInProgress(type="all", brand) {
|
|
|
201
201
|
<br class="clear">
|
|
202
202
|
|
|
203
203
|
<footer>
|
|
204
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on
|
|
204
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Mon Aug 26 2024 20:15:19 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
205
205
|
</footer>
|
|
206
206
|
|
|
207
207
|
<script>prettyPrint();</script>
|
package/docs/sanity.js.html
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Config.html">Config</a><ul class='methods'><li data-type='method'><a href="module-Config.html#~initializeService">initializeService</a></li></ul></li><li><a href="module-Railcontent-Services.html">Railcontent-Services</a><ul class='methods'><li data-type='method'><a href="module-Railcontent-Services.html#.fetchAllCompletedStates">fetchAllCompletedStates</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentInProgress">fetchContentInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchCurrentSongComplete">fetchCurrentSongComplete</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</a></li></ul></li><li><a href="module-Sanity-Services.html">Sanity-Services</a><ul class='methods'><li data-type='method'><a href="module-Sanity-Services.html#.fetchAll">fetchAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllFilterOptions">fetchAllFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllSongs">fetchAllSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchArtists">fetchArtists</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentId">fetchByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentIds">fetchByRailContentIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchChildren">fetchChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCourseOverview">fetchCourseOverview</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchLessonContent">fetchLessonContent</a></li><li data-type='method'><a href="module-Sanity-Services.html#.
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Config.html">Config</a><ul class='methods'><li data-type='method'><a href="module-Config.html#~initializeService">initializeService</a></li></ul></li><li><a href="module-Railcontent-Services.html">Railcontent-Services</a><ul class='methods'><li data-type='method'><a href="module-Railcontent-Services.html#.fetchAllCompletedStates">fetchAllCompletedStates</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchContentInProgress">fetchContentInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchCurrentSongComplete">fetchCurrentSongComplete</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</a></li></ul></li><li><a href="module-Sanity-Services.html">Sanity-Services</a><ul class='methods'><li data-type='method'><a href="module-Sanity-Services.html#.fetchAll">fetchAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllFilterOptions">fetchAllFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchAllSongs">fetchAllSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchArtists">fetchArtists</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentId">fetchByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchByRailContentIds">fetchByRailContentIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCatalogMetadata">fetchCatalogMetadata</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchChildren">fetchChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchCourseOverview">fetchCourseOverview</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchLessonContent">fetchLessonContent</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethod">fetchMethod</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodChildrenIds">fetchMethodChildrenIds</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodNextLesson">fetchMethodNextLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethodPreviousNextLesson">fetchMethodPreviousNextLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchMethods">fetchMethods</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchNewReleases">fetchNewReleases</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchNextPreviousLesson">fetchNextPreviousLesson</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchPackAll">fetchPackAll</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchPackChildren">fetchPackChildren</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchParentByRailContentId">fetchParentByRailContentId</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchRelatedLessons">fetchRelatedLessons</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchRelatedSongs">fetchRelatedSongs</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSanity">fetchSanity</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongArtistCount">fetchSongArtistCount</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongById">fetchSongById</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongCount">fetchSongCount</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchSongFilterOptions">fetchSongFilterOptions</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchUpcomingEvents">fetchUpcomingEvents</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchWorkouts">fetchWorkouts</a></li></ul></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
<pre class="prettyprint source linenums"><code>/**
|
|
49
49
|
* @module Sanity-Services
|
|
50
50
|
*/
|
|
51
|
-
import {contentTypeConfig} from "../contentTypeConfig";
|
|
51
|
+
import {assignmentsField, contentTypeConfig, DEFAULT_FIELDS, getFieldsForContentType} from "../contentTypeConfig";
|
|
52
52
|
import {globalConfig} from "./config";
|
|
53
53
|
|
|
54
54
|
import { fetchAllCompletedStates, fetchCurrentSongComplete } from './railcontent.js';
|
|
@@ -65,25 +65,10 @@ import { fetchAllCompletedStates, fetchCurrentSongComplete } from './railcontent
|
|
|
65
65
|
* .catch(error => console.error(error));
|
|
66
66
|
*/
|
|
67
67
|
export async function fetchSongById(documentId) {
|
|
68
|
-
const fields = [
|
|
69
|
-
'"id": railcontent_id',
|
|
70
|
-
'railcontent_id',
|
|
71
|
-
'"type": _type',
|
|
72
|
-
'description',
|
|
73
|
-
'title',
|
|
74
|
-
'"thumbnail_url": thumbnail.asset->url',
|
|
75
|
-
'"style": genre[0]->name',
|
|
76
|
-
'"artist": artist->name',
|
|
77
|
-
'album',
|
|
78
|
-
'instrumentless',
|
|
79
|
-
'soundslice',
|
|
80
|
-
'"resources": resource[]{resource_url, resource_name}',
|
|
81
|
-
'"url": web_url_path',
|
|
82
|
-
];
|
|
83
68
|
|
|
84
69
|
const query = `
|
|
85
70
|
*[_type == "song" && railcontent_id == ${documentId}]{
|
|
86
|
-
${
|
|
71
|
+
${getFieldsForContentType('song', true)}
|
|
87
72
|
}`;
|
|
88
73
|
|
|
89
74
|
return fetchSanity(query, false);
|
|
@@ -284,10 +269,10 @@ export async function fetchSongCount(brand) {
|
|
|
284
269
|
* Fetch the latest workouts for a specific brand, including completion status and progress.
|
|
285
270
|
* This function retrieves up to five of the latest workout content for a given brand, sorted in descending order by their publication date.
|
|
286
271
|
* It also includes completion status and progress percentage for each workout by fetching additional data about user progress.
|
|
287
|
-
*
|
|
272
|
+
*
|
|
288
273
|
* @param {string} brand - The brand for which to fetch workouts (e.g., 'drumeo', 'pianote').
|
|
289
274
|
* @returns {Promise<Array<Object>|null>} - A promise that resolves to an array of workout data objects with additional properties for completion status and progress percentage, or null if no workouts are found.
|
|
290
|
-
*
|
|
275
|
+
*
|
|
291
276
|
* @example
|
|
292
277
|
* fetchWorkouts('drumeo')
|
|
293
278
|
* .then(workouts => console.log(workouts))
|
|
@@ -298,12 +283,12 @@ export async function fetchWorkouts(brand) {
|
|
|
298
283
|
"id": railcontent_id,
|
|
299
284
|
title,
|
|
300
285
|
"image": thumbnail.asset->url,
|
|
301
|
-
|
|
302
|
-
|
|
286
|
+
${artistOrInstructor()},
|
|
287
|
+
${artistOrInstructorAsArray()},
|
|
303
288
|
difficulty,
|
|
304
289
|
difficulty_string,
|
|
305
290
|
length_in_seconds,
|
|
306
|
-
published_on
|
|
291
|
+
published_on,;
|
|
307
292
|
"type": _type,
|
|
308
293
|
web_url_path,
|
|
309
294
|
} | order(published_on desc)[0...5]`
|
|
@@ -391,17 +376,9 @@ export async function fetchUpcomingEvents(brand) {
|
|
|
391
376
|
* .then(content => console.log(content))
|
|
392
377
|
* .catch(error => console.error(error));
|
|
393
378
|
*/
|
|
394
|
-
export async function fetchByRailContentId(id) {
|
|
379
|
+
export async function fetchByRailContentId(id, contentType) {
|
|
395
380
|
const query = `*[railcontent_id == ${id}]{
|
|
396
|
-
|
|
397
|
-
title,
|
|
398
|
-
"image": thumbnail.asset->url,
|
|
399
|
-
"artist_name": artist->name,
|
|
400
|
-
artist,
|
|
401
|
-
difficulty,
|
|
402
|
-
difficulty_string,
|
|
403
|
-
web_url_path,
|
|
404
|
-
published_on
|
|
381
|
+
${getFieldsForContentType(contentType)}
|
|
405
382
|
}`
|
|
406
383
|
return fetchSanity(query, false);
|
|
407
384
|
}
|
|
@@ -410,6 +387,7 @@ export async function fetchByRailContentId(id) {
|
|
|
410
387
|
* Fetch content by an array of Railcontent IDs.
|
|
411
388
|
*
|
|
412
389
|
* @param {Array<string>} ids - The array of Railcontent IDs of the content to fetch.
|
|
390
|
+
* @param {string} [contentType] - The content type the IDs to add needed fields to the response.
|
|
413
391
|
* @returns {Promise<Array<Object>|null>} - A promise that resolves to an array of content objects or null if not found.
|
|
414
392
|
*
|
|
415
393
|
* @example
|
|
@@ -417,18 +395,10 @@ export async function fetchByRailContentId(id) {
|
|
|
417
395
|
* .then(contents => console.log(contents))
|
|
418
396
|
* .catch(error => console.error(error));
|
|
419
397
|
*/
|
|
420
|
-
export async function fetchByRailContentIds(ids) {
|
|
398
|
+
export async function fetchByRailContentIds(ids, contentType = undefined) {
|
|
421
399
|
const idsString = ids.join(',');
|
|
422
400
|
const query = `*[railcontent_id in [${idsString}]]{
|
|
423
|
-
|
|
424
|
-
title,
|
|
425
|
-
"image": thumbnail.asset->url,
|
|
426
|
-
"artist_name": artist->name,
|
|
427
|
-
artist,
|
|
428
|
-
difficulty,
|
|
429
|
-
difficulty_string,
|
|
430
|
-
web_url_path,
|
|
431
|
-
published_on
|
|
401
|
+
${getFieldsForContentType(contentType)}
|
|
432
402
|
}`
|
|
433
403
|
return fetchSanity(query, true);
|
|
434
404
|
}
|
|
@@ -489,50 +459,9 @@ export async function fetchAll(brand, type, {
|
|
|
489
459
|
: "";
|
|
490
460
|
|
|
491
461
|
// Determine the sort order
|
|
492
|
-
|
|
493
|
-
switch (sort) {
|
|
494
|
-
case "slug":
|
|
495
|
-
if(groupBy){
|
|
496
|
-
sortOrder = "name asc";
|
|
497
|
-
} else {
|
|
498
|
-
sortOrder = "title asc";
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
break;
|
|
502
|
-
case "published_on":
|
|
503
|
-
sortOrder = "published_on asc";
|
|
504
|
-
break;
|
|
505
|
-
case "-published_on":
|
|
506
|
-
sortOrder = "published_on desc";
|
|
507
|
-
break;
|
|
508
|
-
case "-slug":
|
|
509
|
-
if(groupBy){
|
|
510
|
-
sortOrder = "name desc";
|
|
511
|
-
} else {
|
|
512
|
-
sortOrder = "title desc";
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
break;
|
|
516
|
-
case "-popularity":
|
|
517
|
-
sortOrder = "popularity desc";
|
|
518
|
-
break;
|
|
519
|
-
default:
|
|
520
|
-
sortOrder = "published_on asc";
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
462
|
+
const sortOrder = getSortOrder(sort);
|
|
523
463
|
|
|
524
|
-
let
|
|
525
|
-
'"id": railcontent_id',
|
|
526
|
-
'railcontent_id',
|
|
527
|
-
'"type": _type',
|
|
528
|
-
'title',
|
|
529
|
-
'"image": thumbnail.asset->url',
|
|
530
|
-
'difficulty',
|
|
531
|
-
'difficulty_string',
|
|
532
|
-
'web_url_path',
|
|
533
|
-
'published_on'];
|
|
534
|
-
|
|
535
|
-
let fields = defaultFields.concat(additionalFields);
|
|
464
|
+
let fields = DEFAULT_FIELDS.concat(additionalFields);
|
|
536
465
|
let fieldsString = fields.join(',');
|
|
537
466
|
|
|
538
467
|
// Determine the group by clause
|
|
@@ -589,6 +518,28 @@ export async function fetchAll(brand, type, {
|
|
|
589
518
|
return fetchSanity(query, true);
|
|
590
519
|
}
|
|
591
520
|
|
|
521
|
+
export function getSortOrder(sort= '-published_on', groupBy)
|
|
522
|
+
{
|
|
523
|
+
// Determine the sort order
|
|
524
|
+
let sortOrder = '';
|
|
525
|
+
const isDesc = sort.startsWith('-');
|
|
526
|
+
sort = isDesc ? sort.substring(1) : sort;
|
|
527
|
+
switch (sort) {
|
|
528
|
+
case "slug":
|
|
529
|
+
sortOrder = groupBy ? 'name' : "title";
|
|
530
|
+
break;
|
|
531
|
+
case "popularity":
|
|
532
|
+
sortOrder = "popularity";
|
|
533
|
+
break;
|
|
534
|
+
case "published_on":
|
|
535
|
+
default:
|
|
536
|
+
sortOrder = "published_on";
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
sortOrder += isDesc ? ' desc' : ' asc';
|
|
540
|
+
return sortOrder;
|
|
541
|
+
}
|
|
542
|
+
|
|
592
543
|
/**
|
|
593
544
|
* Fetches all available filter options based on various criteria such as brand, filters, style, artist, content type, and search term.
|
|
594
545
|
*
|
|
@@ -626,10 +577,10 @@ export async function fetchAllFilterOptions(
|
|
|
626
577
|
return `&& ${key} == "${value}"`;
|
|
627
578
|
}).join(' ')
|
|
628
579
|
: undefined;
|
|
629
|
-
|
|
580
|
+
|
|
630
581
|
const commonFilter = `_type == '${contentType}' && brand == "${brand}"${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} ${filtersToGroq ? filtersToGroq : ''}`;
|
|
631
582
|
const query = `
|
|
632
|
-
{
|
|
583
|
+
{
|
|
633
584
|
"meta": {
|
|
634
585
|
"totalResults": count(*[${commonFilter}
|
|
635
586
|
${term ? ` && (title match "${term}" || album match "${term}" || artist->name match "${term}" || genre[]->name match "${term}")` : ''}]),
|
|
@@ -658,22 +609,33 @@ export async function fetchAllFilterOptions(
|
|
|
658
609
|
/**
|
|
659
610
|
* Fetch children content by Railcontent ID.
|
|
660
611
|
* @param {string} railcontentId - The Railcontent ID of the parent content.
|
|
661
|
-
* @returns {Promise<Array<Object>|null>} - The fetched children content data or
|
|
612
|
+
* @returns {Promise<Array<Object>|null>} - The fetched children content data or [] if not found.
|
|
662
613
|
*/
|
|
663
614
|
export async function fetchChildren(railcontentId) {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
615
|
+
const query = `*[railcontent_id == ${railcontentId}]{
|
|
616
|
+
'children': child[]->{
|
|
617
|
+
${getFieldsForContentType()}
|
|
618
|
+
},
|
|
619
|
+
}[0..1]`;
|
|
620
|
+
let parent = await fetchSanity(query, true);
|
|
621
|
+
return parent[0]['children'] ?? [];
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
*
|
|
626
|
+
* @param railcontentId - railcontent id of the child
|
|
627
|
+
* @returns {Promise<Array<string>|null>} - The fetched parent content data or [] if not found
|
|
628
|
+
*/
|
|
629
|
+
export async function fetchParentByRailContentId(railcontentId) {
|
|
630
|
+
const query = `*[railcontent_id == ${railcontentId}]{
|
|
631
|
+
'parents': array::unique([
|
|
632
|
+
...(*[references(^._id)]{
|
|
633
|
+
${getFieldsForContentType()}
|
|
634
|
+
})
|
|
635
|
+
])
|
|
636
|
+
}[0...1]`;
|
|
637
|
+
let child = await fetchSanity(query, true);
|
|
638
|
+
return child[0]['parents'][0] ?? [];
|
|
677
639
|
}
|
|
678
640
|
|
|
679
641
|
/**
|
|
@@ -682,49 +644,79 @@ export async function fetchChildren(railcontentId) {
|
|
|
682
644
|
* @returns {Promise<Object|null>} - The fetched methods data or null if not found.
|
|
683
645
|
*/
|
|
684
646
|
export async function fetchMethods(brand) {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
"instructors":instructor[]->name,
|
|
691
|
-
length_in_seconds,
|
|
692
|
-
permission,
|
|
693
|
-
popularity,
|
|
694
|
-
published_on,
|
|
695
|
-
railcontent_id,
|
|
696
|
-
"slug": slug.current,
|
|
697
|
-
status,
|
|
698
|
-
"thumbnail": thumbnail.asset->url,
|
|
699
|
-
"thumbnail_logo": logo_image_url.asset->url,
|
|
700
|
-
title,
|
|
701
|
-
total_xp,
|
|
702
|
-
"type": _type,
|
|
703
|
-
web_url_path,
|
|
704
|
-
xp
|
|
647
|
+
//TODOS
|
|
648
|
+
//ADD INSTRUCTORS AND POSITION
|
|
649
|
+
const query = `*[_type == 'learning-path' && brand == '${brand}'] {
|
|
650
|
+
${getFieldsForContentType('method')}
|
|
651
|
+
"position": count(*[_type == 'learning-path' && brand == '${brand}' && (published_on < ^.published_on || (published_on == ^.published_on && _id < ^._id))]) + 1,
|
|
705
652
|
} | order(published_on asc)`
|
|
706
653
|
return fetchSanity(query, true);
|
|
707
654
|
}
|
|
708
655
|
|
|
656
|
+
/**
|
|
657
|
+
* Fetch the Method (learning-paths) for a specific brand.
|
|
658
|
+
* @param {string} brand - The brand for which to fetch methods.
|
|
659
|
+
* @param {string} slug - The slug of the method.
|
|
660
|
+
* @returns {Promise<Object|null>} - The fetched methods data or null if not found.
|
|
661
|
+
*/
|
|
662
|
+
export async function fetchMethod(brand, slug) {
|
|
663
|
+
const query = `*[_type == 'learning-path' && brand == "${brand}" && slug.current == "${slug}"] {
|
|
664
|
+
"description": description[0].children[0].text,
|
|
665
|
+
"instructors":instructor[]->name,
|
|
666
|
+
published_on,
|
|
667
|
+
"id": railcontent_id,
|
|
668
|
+
railcontent_id,
|
|
669
|
+
"slug": slug.current,
|
|
670
|
+
status,
|
|
671
|
+
title,
|
|
672
|
+
video,
|
|
673
|
+
"type": _type,
|
|
674
|
+
"levels": child[]->
|
|
675
|
+
{
|
|
676
|
+
"id": railcontent_id,
|
|
677
|
+
published_on,
|
|
678
|
+
"thumbnail_url": thumbnail.asset->url,
|
|
679
|
+
"instructor": instructor[]->{name},
|
|
680
|
+
title,
|
|
681
|
+
"description": description[0].children[0].text,
|
|
682
|
+
}
|
|
683
|
+
} | order(published_on asc)`
|
|
684
|
+
return fetchSanity(query, false);
|
|
685
|
+
}
|
|
686
|
+
|
|
709
687
|
/**
|
|
710
688
|
* Fetch the next lesson for a specific method by Railcontent ID.
|
|
711
689
|
* @param {string} railcontentId - The Railcontent ID of the current lesson.
|
|
690
|
+
* @param {string} methodId - The RailcontentID of the method
|
|
712
691
|
* @returns {Promise<Object|null>} - The fetched next lesson data or null if not found.
|
|
713
692
|
*/
|
|
714
|
-
export async function fetchMethodNextLesson(railcontentId) {
|
|
715
|
-
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
693
|
+
export async function fetchMethodNextLesson(railcontentId, methodId) {
|
|
694
|
+
const sortedChildren = await fetchMethodChildrenIds(methodId);
|
|
695
|
+
const index = sortedChildren.indexOf(railcontentId);
|
|
696
|
+
const childIndex = sortedChildren[index + 1];
|
|
697
|
+
return childIndex ? await fetchByRailContentId(childIndex) : null;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Fetch the next lesson for a specific method by Railcontent ID.
|
|
703
|
+
* @param {string} railcontentId - The Railcontent ID of the current lesson.
|
|
704
|
+
* @param {string} methodId - The RailcontentID of the method
|
|
705
|
+
* @returns {Promise<Object|null>} - object with `nextLesson` and `previousLesson` attributes
|
|
706
|
+
* @example
|
|
707
|
+
* fetchMethodPreviousNextLesson(241284, 241247)
|
|
708
|
+
* .then(data => { console.log('nextLesson', data.nextLesson); console.log('prevlesson', data.prevLesson);})
|
|
709
|
+
* .catch(error => console.error(error));
|
|
710
|
+
*/
|
|
711
|
+
export async function fetchMethodPreviousNextLesson(railcontentId, methodId) {
|
|
712
|
+
const sortedChildren = await fetchMethodChildrenIds(methodId);
|
|
713
|
+
const index = sortedChildren.indexOf(railcontentId);
|
|
714
|
+
let nextId = sortedChildren[index + 1];
|
|
715
|
+
let previousId = sortedChildren[index -1];
|
|
716
|
+
let nextPrev = await fetchByRailContentIds([nextId, previousId]);
|
|
717
|
+
const nextLesson = nextPrev.find((elem) => {return elem['id'] === nextId});
|
|
718
|
+
const prevLesson = nextPrev.find((elem) => {return elem['id'] === previousId});
|
|
719
|
+
return {nextLesson, prevLesson};
|
|
728
720
|
}
|
|
729
721
|
|
|
730
722
|
/**
|
|
@@ -732,11 +724,37 @@ export async function fetchMethodNextLesson(railcontentId) {
|
|
|
732
724
|
* @param {string} railcontentId - The Railcontent ID of the method.
|
|
733
725
|
* @returns {Promise<Array<Object>|null>} - The fetched children data or null if not found.
|
|
734
726
|
*/
|
|
735
|
-
export async function
|
|
727
|
+
export async function fetchMethodChildrenIds(railcontentId) {
|
|
736
728
|
//TODO: Implement getByParentId include sum XP
|
|
737
|
-
|
|
729
|
+
const query = `*[_type == 'learning-path' && railcontent_id == ${railcontentId}]{
|
|
730
|
+
'children': child[]-> {
|
|
731
|
+
'id': railcontent_id,
|
|
732
|
+
'children': child[]-> {
|
|
733
|
+
'id': railcontent_id,
|
|
734
|
+
'children': child[]-> {
|
|
735
|
+
'id': railcontent_id,
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}`;
|
|
740
|
+
let allChildren = await fetchSanity(query, false);
|
|
741
|
+
return getChildrenToDepth(allChildren, 4);;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function getChildrenToDepth(parent, depth = 1)
|
|
745
|
+
{
|
|
746
|
+
let allChildrenIds = [];
|
|
747
|
+
if (parent['children']) {
|
|
748
|
+
parent['children'].forEach((child) => {
|
|
749
|
+
allChildrenIds.push(child['id']);
|
|
750
|
+
allChildrenIds = allChildrenIds.concat(getChildrenToDepth(child, depth-1));
|
|
751
|
+
})
|
|
752
|
+
}
|
|
753
|
+
return allChildrenIds;
|
|
738
754
|
}
|
|
739
755
|
|
|
756
|
+
|
|
757
|
+
|
|
740
758
|
/**
|
|
741
759
|
* Fetch the next and previous lessons for a specific lesson by Railcontent ID.
|
|
742
760
|
* @param {string} railcontentId - The Railcontent ID of the current lesson.
|
|
@@ -775,22 +793,15 @@ export async function fetchLessonContent(railContentId) {
|
|
|
775
793
|
chapter_description,
|
|
776
794
|
chapter_timecode,
|
|
777
795
|
"chapter_thumbnail_url": chapter_thumbnail_url.asset->url
|
|
778
|
-
},
|
|
796
|
+
},
|
|
779
797
|
"coaches": instructor[]-> {
|
|
780
|
-
name,
|
|
798
|
+
name,
|
|
781
799
|
"id":_id,
|
|
782
800
|
"coach_profile_image":thumbnail_url.asset->url
|
|
783
801
|
},
|
|
784
802
|
"instructors":instructor[]->name,
|
|
785
803
|
instructor[]->,
|
|
786
|
-
|
|
787
|
-
"id": railcontent_id,
|
|
788
|
-
"soundslice_slug": assignment_soundslice,
|
|
789
|
-
"title": assignment_title,
|
|
790
|
-
"sheet_music_image_url": assignment_sheet_music_image,
|
|
791
|
-
"timecode": assignment_timecode,
|
|
792
|
-
"description": assignment_description
|
|
793
|
-
},
|
|
804
|
+
${assignmentsField}
|
|
794
805
|
video}`
|
|
795
806
|
return fetchSanity(query, false);
|
|
796
807
|
}
|
|
@@ -856,7 +867,7 @@ export async function fetchPackChildren(railcontentId) {
|
|
|
856
867
|
* Fetch the data needed for the Course Overview screen.
|
|
857
868
|
* @param {string} id - The Railcontent ID of the course
|
|
858
869
|
* @returns {Promise<Object|null>} - The course information and lessons or null if not found.
|
|
859
|
-
*
|
|
870
|
+
*
|
|
860
871
|
* @example
|
|
861
872
|
* fetchCourseOverview('course123')
|
|
862
873
|
* .then(course => console.log(course))
|
|
@@ -941,6 +952,32 @@ export async function fetchSanity(query, isList) {
|
|
|
941
952
|
}
|
|
942
953
|
}
|
|
943
954
|
|
|
955
|
+
/**
|
|
956
|
+
* Fetch CatalogueMetadata from Sanity. This information may be duplicated in the contentTypeConfig.js.
|
|
957
|
+
* It's an ongoing discussion (Aug 2024), but it's been included here if necessary
|
|
958
|
+
*
|
|
959
|
+
* @param {string} contentType - name of the contentype to pull
|
|
960
|
+
* @returns {Promise<Object|null>} - A promise that resolves to the fetched data or null if an error occurs or no results are found.
|
|
961
|
+
*
|
|
962
|
+
* @example
|
|
963
|
+
*
|
|
964
|
+
* fetchCatalogMetadata('song')
|
|
965
|
+
* .then(data => console.log(data))
|
|
966
|
+
* .catch(error => console.error(error));
|
|
967
|
+
*/
|
|
968
|
+
export async function fetchCatalogMetadata(contentType)
|
|
969
|
+
{ const query = `*[_type == 'CatalogMetadata']{
|
|
970
|
+
catalog_type,
|
|
971
|
+
brand,
|
|
972
|
+
groq_results,
|
|
973
|
+
groq_search_fields,
|
|
974
|
+
meta_data_groq,
|
|
975
|
+
modal_text,
|
|
976
|
+
sort_by,
|
|
977
|
+
}`
|
|
978
|
+
return fetchSanity(query, false);
|
|
979
|
+
}
|
|
980
|
+
|
|
944
981
|
|
|
945
982
|
//Helper Functions
|
|
946
983
|
function arrayJoinWithQuotes(array, delimiter = ',') {
|
|
@@ -971,6 +1008,8 @@ function checkSanityConfig(config) {
|
|
|
971
1008
|
}
|
|
972
1009
|
return true;
|
|
973
1010
|
}
|
|
1011
|
+
|
|
1012
|
+
|
|
974
1013
|
</code></pre>
|
|
975
1014
|
</article>
|
|
976
1015
|
</section>
|
|
@@ -985,7 +1024,7 @@ function checkSanityConfig(config) {
|
|
|
985
1024
|
<br class="clear">
|
|
986
1025
|
|
|
987
1026
|
<footer>
|
|
988
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on
|
|
1027
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Mon Aug 26 2024 20:15:19 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
989
1028
|
</footer>
|
|
990
1029
|
|
|
991
1030
|
<script>prettyPrint();</script>
|
package/package.json
CHANGED
package/src/contentTypeConfig.js
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
|
+
const DEFAULT_FIELDS = [
|
|
2
|
+
"'sanity_id' : _id",
|
|
3
|
+
"'id': railcontent_id",
|
|
4
|
+
'railcontent_id',
|
|
5
|
+
artistOrInstructorName(),
|
|
6
|
+
"artist",
|
|
7
|
+
"title",
|
|
8
|
+
"'image': thumbnail.asset->url",
|
|
9
|
+
"'thumbnail': thumbnail.asset->url",
|
|
10
|
+
"difficulty",
|
|
11
|
+
"difficulty_string",
|
|
12
|
+
"web_url_path",
|
|
13
|
+
"published_on",
|
|
14
|
+
"'type': _type",
|
|
15
|
+
"progress_percent",
|
|
16
|
+
"'length_in_seconds' : coalesce(length_in_seconds, soundslice[0].soundslice_length_in_second)",
|
|
17
|
+
"brand",
|
|
18
|
+
"'genre': genre[]->name",
|
|
19
|
+
'status',
|
|
20
|
+
"'slug' : slug.current",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const descriptionField = 'description[0].children[0].text';
|
|
24
|
+
|
|
25
|
+
const assignmentsField = `"assignments":assignment[]{
|
|
26
|
+
"id": railcontent_id,
|
|
27
|
+
"soundslice_slug": assignment_soundslice,
|
|
28
|
+
"title": assignment_title,
|
|
29
|
+
"sheet_music_image_url": assignment_sheet_music_image,
|
|
30
|
+
"timecode": assignment_timecode,
|
|
31
|
+
"description": assignment_description
|
|
32
|
+
},`
|
|
33
|
+
|
|
1
34
|
let contentTypeConfig = {
|
|
2
35
|
'song': {
|
|
3
36
|
'fields': [
|
|
4
|
-
'"artist_name": artist->name',
|
|
5
37
|
'soundslice',
|
|
6
38
|
'instrumentless',
|
|
7
39
|
],
|
|
@@ -33,9 +65,46 @@ let contentTypeConfig = {
|
|
|
33
65
|
'"instructors": instructor[]->name',
|
|
34
66
|
]
|
|
35
67
|
},
|
|
68
|
+
'method': {
|
|
69
|
+
'fields': [
|
|
70
|
+
`"description": ${descriptionField}`,
|
|
71
|
+
'hide_from_recsys',
|
|
72
|
+
'"image": thumbnail.asset->url',
|
|
73
|
+
'"instructors":instructor[]->name',
|
|
74
|
+
'"lesson_count": child_count',
|
|
75
|
+
'length_in_seconds',
|
|
76
|
+
'permission',
|
|
77
|
+
'popularity',
|
|
78
|
+
'published_on',
|
|
79
|
+
'railcontent_id',
|
|
80
|
+
'"thumbnail_logo": logo_image_url.asset->url',
|
|
81
|
+
'title',
|
|
82
|
+
'total_xp',
|
|
83
|
+
'"type": _type',
|
|
84
|
+
'"url": web_url_path',
|
|
85
|
+
'xp',
|
|
86
|
+
]
|
|
87
|
+
}
|
|
36
88
|
}
|
|
37
89
|
|
|
90
|
+
function artistOrInstructorName(key='artist_name') {
|
|
91
|
+
return `'${key}': coalesce(artist->name, instructor[0]->name)`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function artistOrInstructorNameAsArray(key='artists') {
|
|
95
|
+
return `'${key}': select(artist->name != null => [artist->name], instructor[]->name)`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getFieldsForContentType(contentType, asQueryString=true) {
|
|
99
|
+
const fields = contentType ? DEFAULT_FIELDS.concat(contentTypeConfig?.[contentType]?.fields ?? []) : DEFAULT_FIELDS;
|
|
100
|
+
return asQueryString ? fields.toString() + ',' : fields;
|
|
101
|
+
}
|
|
38
102
|
|
|
39
103
|
module.exports = {
|
|
40
|
-
contentTypeConfig
|
|
104
|
+
contentTypeConfig,
|
|
105
|
+
artistOrInstructorName,
|
|
106
|
+
artistOrInstructorNameAsArray,
|
|
107
|
+
getFieldsForContentType,
|
|
108
|
+
DEFAULT_FIELDS,
|
|
109
|
+
assignmentsField
|
|
41
110
|
}
|