musora-content-services 1.0.107 → 1.0.109

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.
Files changed (55) hide show
  1. package/.github/workflows/node.js.yml +0 -0
  2. package/CHANGELOG.md +4 -0
  3. package/README.md +0 -0
  4. package/babel.config.js +0 -0
  5. package/docs/config.js.html +2 -2
  6. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  7. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  8. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  9. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  10. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  11. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  12. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  13. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  14. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  15. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
  16. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  17. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  18. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  19. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  20. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
  21. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  24. package/docs/index.html +2 -2
  25. package/docs/module-Config.html +2 -2
  26. package/docs/module-Railcontent-Services.html +2 -2
  27. package/docs/module-Sanity-Services.html +393 -42
  28. package/docs/railcontent.js.html +2 -2
  29. package/docs/sanity.js.html +307 -86
  30. package/docs/scripts/collapse.js +0 -0
  31. package/docs/scripts/commonNav.js +0 -0
  32. package/docs/scripts/linenumber.js +0 -0
  33. package/docs/scripts/nav.js +0 -0
  34. package/docs/scripts/polyfill.js +0 -0
  35. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -0
  36. package/docs/scripts/prettify/lang-css.js +0 -0
  37. package/docs/scripts/prettify/prettify.js +0 -0
  38. package/docs/scripts/search.js +0 -0
  39. package/docs/styles/jsdoc.css +0 -0
  40. package/docs/styles/prettify.css +0 -0
  41. package/jest.config.js +0 -0
  42. package/jsdoc.json +0 -0
  43. package/package.json +1 -1
  44. package/src/contentTypeConfig.js +1330 -11
  45. package/src/filterBuilder.js +0 -0
  46. package/src/index.d.ts +4 -0
  47. package/src/index.js +4 -0
  48. package/src/services/config.js +0 -0
  49. package/src/services/railcontent.js +0 -0
  50. package/src/services/sanity.js +68 -3
  51. package/src/services/userContext.js +0 -0
  52. package/test/localStorageMock.js +0 -0
  53. package/test/log.js +0 -0
  54. package/test/sanityQueryService.test.js +15 -0
  55. package/test/userContext.test.js +0 -0
@@ -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#.fetchCompletedContent">fetchCompletedContent</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchCompletedState">fetchCompletedState</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#.fetchContentPageUserData">fetchContentPageUserData</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchVimeoData">fetchVimeoData</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#.fetchAllPacks">fetchAllPacks</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#.fetchArtistLessons">fetchArtistLessons</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#.fetchByReference">fetchByReference</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#.fetchChallengeOverview">fetchChallengeOverview</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#.fetchCoachLessons">fetchCoachLessons</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#.fetchFoundation">fetchFoundation</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchGenreLessons">fetchGenreLessons</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#.fetchMethodChildren">fetchMethodChildren</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#.fetchRelatedMethodLessons">fetchRelatedMethodLessons</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#.fetchScheduledReleases">fetchScheduledReleases</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>
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#.fetchCompletedContent">fetchCompletedContent</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchCompletedState">fetchCompletedState</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#.fetchContentPageUserData">fetchContentPageUserData</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchSongsInProgress">fetchSongsInProgress</a></li><li data-type='method'><a href="module-Railcontent-Services.html#.fetchVimeoData">fetchVimeoData</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#.fetchAllPacks">fetchAllPacks</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#.fetchArtistLessons">fetchArtistLessons</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#.fetchByReference">fetchByReference</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#.fetchChallengeOverview">fetchChallengeOverview</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#.fetchCoachLessons">fetchCoachLessons</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#.fetchFoundation">fetchFoundation</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchGenreLessons">fetchGenreLessons</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#.fetchMetadata">fetchMetadata</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#.fetchMethodChildren">fetchMethodChildren</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#.fetchRelatedMethodLessons">fetchRelatedMethodLessons</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#.fetchScheduledReleases">fetchScheduledReleases</a></li><li data-type='method'><a href="module-Sanity-Services.html#.fetchShowsData">fetchShowsData</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
 
@@ -59,10 +59,13 @@ import {
59
59
  filtersToGroq,
60
60
  getUpcomingEventsTypes,
61
61
  getNewReleasesTypes,
62
+ showsTypes,
63
+ contentMetadata
62
64
  } from "../contentTypeConfig";
63
65
  import {globalConfig} from "./config";
64
66
 
65
67
  import { fetchAllCompletedStates, fetchCurrentSongComplete } from './railcontent.js';
68
+ import {arrayToStringRepresentation, FilterBuilder} from "../filterBuilder";
66
69
 
67
70
  /**
68
71
  * Fetch a song by its document ID from Sanity.
@@ -76,12 +79,15 @@ import { fetchAllCompletedStates, fetchCurrentSongComplete } from './railcontent
76
79
  * .catch(error => console.error(error));
77
80
  */
78
81
  export async function fetchSongById(documentId) {
79
-
80
- const query = `
81
- *[_type == "song" &amp;&amp; railcontent_id == ${documentId}]{
82
- ${getFieldsForContentType('song', true)}
83
- }`;
84
-
82
+ const fields = getFieldsForContentType('song');
83
+ const filterParams = {};
84
+ const query = buildQuery(
85
+ `_type == "song" &amp;&amp; railcontent_id == ${documentId}`,
86
+ filterParams,
87
+ fields,
88
+ {
89
+ isSingle: true,
90
+ });
85
91
  return fetchSanity(query, false);
86
92
  }
87
93
 
@@ -97,10 +103,11 @@ export async function fetchSongById(documentId) {
97
103
  * .catch(error => console.error(error));
98
104
  */
99
105
  export async function fetchArtists(brand) {
106
+ const filter = new FilterBuilder(`_type == "song" &amp;&amp; brand == "${brand}" &amp;&amp; references(^._id)`).buildFilter();
100
107
  const query = `
101
108
  *[_type == "artist"]{
102
109
  name,
103
- "lessonsCount": count(*[_type == "song" &amp;&amp; brand == "${brand}" &amp;&amp; references(^._id)])
110
+ "lessonsCount": count(*[${filter}])
104
111
  }[lessonsCount > 0]`;
105
112
  return fetchSanity(query, true);
106
113
  }
@@ -301,23 +308,32 @@ export async function fetchWorkouts(brand) {
301
308
  */
302
309
  export async function fetchNewReleases(brand, { page = 1, limit = 10, sort="-published_on" } = {}) {
303
310
  const newTypes = getNewReleasesTypes(brand);
304
- const typesString = arrayJoinWithQuotes(newTypes);
311
+ const typesString = arrayToStringRepresentation(newTypes);
305
312
  const start = (page - 1) * limit;
306
313
  const end = start + limit;
307
314
  const sortOrder = getSortOrder(sort);
308
- const query = `*[_type in [${typesString}] &amp;&amp; brand == '${brand}']{
309
- "id": railcontent_id,
310
- title,
311
- "image": thumbnail.asset->url,
312
- "artist_name": instructor[0]->name,
313
- "artists": instructor[]->name,
314
- difficulty,
315
- difficulty_string,
316
- length_in_seconds,
317
- published_on,
318
- "type": _type,
319
- web_url_path,
320
- } | order(${sortOrder})[${start}..${end}]`
315
+ const filter = `_type in ${typesString} &amp;&amp; brand == '${brand}'`;
316
+ const fields = `
317
+ "id": railcontent_id,
318
+ title,
319
+ "image": thumbnail.asset->url,
320
+ "artist_name": instructor[0]->name,
321
+ "artists": instructor[]->name,
322
+ difficulty,
323
+ difficulty_string,
324
+ length_in_seconds,
325
+ published_on,
326
+ "type": _type,
327
+ web_url_path,`;
328
+ const filterParams = {};
329
+ const query = buildQuery(
330
+ filter,
331
+ filterParams,
332
+ fields,
333
+ {
334
+ sortOrder: sortOrder,
335
+ end: end,
336
+ });
321
337
  return fetchSanity(query, true);
322
338
  }
323
339
 
@@ -338,11 +354,11 @@ export async function fetchNewReleases(brand, { page = 1, limit = 10, sort="-pub
338
354
  */
339
355
  export async function fetchUpcomingEvents(brand, { page = 1, limit = 10 } = {}) {
340
356
  const liveTypes = getUpcomingEventsTypes(brand);
341
- const typesString = arrayJoinWithQuotes(liveTypes);
357
+ const typesString = arrayToStringRepresentation(liveTypes);
342
358
  const now = getSanityDate(new Date());
343
359
  const start = (page - 1) * limit;
344
360
  const end = start + limit;
345
- const query = `*[_type in [${typesString}] &amp;&amp; brand == '${brand}' &amp;&amp; published_on > '${now}' &amp;&amp; status == 'scheduled']{
361
+ const fields = `
346
362
  "id": railcontent_id,
347
363
  title,
348
364
  "image": thumbnail.asset->url,
@@ -353,8 +369,16 @@ export async function fetchUpcomingEvents(brand, { page = 1, limit = 10 } = {})
353
369
  length_in_seconds,
354
370
  published_on,
355
371
  "type": _type,
356
- web_url_path,
357
- } | order(published_on asc)[${start}...${end}]`;
372
+ web_url_path,`;
373
+ const query = buildRawQuery(
374
+ `_type in ${typesString} &amp;&amp; brand == '${brand}' &amp;&amp; published_on > '${now}' &amp;&amp; status == 'scheduled'`,
375
+ fields,
376
+ {
377
+ sortOrder: 'published_on asc',
378
+ start: start,
379
+ end: end,
380
+ },
381
+ );
358
382
  return fetchSanity(query, true);
359
383
  }
360
384
 
@@ -401,6 +425,7 @@ export async function fetchScheduledReleases(brand, { page = 1, limit = 10 }) {
401
425
  * Fetch content by a specific Railcontent ID.
402
426
  *
403
427
  * @param {string} id - The Railcontent ID of the content to fetch.
428
+ * @param {string} contentType - The document type of content to fetch
404
429
  * @returns {Promise&lt;Object|null>} - A promise that resolves to the content object or null if not found.
405
430
  *
406
431
  * @example
@@ -409,10 +434,16 @@ export async function fetchScheduledReleases(brand, { page = 1, limit = 10 }) {
409
434
  * .catch(error => console.error(error));
410
435
  */
411
436
  export async function fetchByRailContentId(id, contentType) {
412
- const query = `*[railcontent_id == ${id}]{
413
- ${getFieldsForContentType(contentType)}
414
- }`
415
- return fetchSanity(query, false);
437
+
438
+ const query = buildRawQuery(
439
+ `railcontent_id == ${id} &amp;&amp; _type == '${contentType}'`,
440
+ getFieldsForContentType(contentType),
441
+ {
442
+ isSingle: true,
443
+ },
444
+ );
445
+
446
+ return fetchSanity(query, false);
416
447
  }
417
448
 
418
449
  /**
@@ -429,6 +460,7 @@ export async function fetchByRailContentId(id, contentType) {
429
460
  */
430
461
  export async function fetchByRailContentIds(ids, contentType = undefined) {
431
462
  const idsString = ids.join(',');
463
+
432
464
  const query = `*[railcontent_id in [${idsString}]]{
433
465
  ${getFieldsForContentType(contentType)}
434
466
  }`
@@ -484,6 +516,9 @@ export async function fetchAll(brand, type, {
484
516
  const start = (page - 1) * limit;
485
517
  const end = start + limit;
486
518
 
519
+ // Construct the type filter
520
+ const typeFilter = type ? `&amp;&amp; _type == '${type}'` : "";
521
+
487
522
  // Construct the search filter
488
523
  const searchFilter = searchTerm
489
524
  ? groupBy !== "" ?
@@ -512,8 +547,8 @@ export async function fetchAll(brand, type, {
512
547
  let webUrlPath = 'artists';
513
548
  query = `
514
549
  {
515
- "total": count(*[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]),
516
- "entity": *[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]
550
+ "total": count(*[_type == '${groupBy}' &amp;&amp; count(*[brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]),
551
+ "entity": *[_type == '${groupBy}' &amp;&amp; count(*[brand == '${brand}' &amp;&amp; ^._id == ${groupBy}._ref ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]
517
552
  {
518
553
  'id': _id,
519
554
  'type': _type,
@@ -533,16 +568,16 @@ export async function fetchAll(brand, type, {
533
568
  let webUrlPath = (groupBy == 'genre')?'/genres':'';
534
569
  query = `
535
570
  {
536
- "total": count(*[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]),
537
- "entity": *[_type == '${groupBy}' &amp;&amp; count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]
571
+ "total": count(*[_type == '${groupBy}' &amp;&amp; count(*[brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]),
572
+ "entity": *[_type == '${groupBy}' &amp;&amp; count(*[brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id) > 0]
538
573
  {
539
574
  'id': _id,
540
575
  'type': _type,
541
576
  name,
542
577
  'head_shot_picture_url': thumbnail_url.asset->url,
543
578
  'web_url_path': select(defined(web_url_path)=> web_url_path +'?included_fieds[]=type,${type}',!defined(web_url_path)=> '/${brand}${webUrlPath}/'+name+'/${webUrlPathType}'),
544
- 'all_lessons_count': count(*[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id),
545
- 'lessons': *[_type == '${type}' &amp;&amp; brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${searchFilter} ${includedFieldsFilter} ${progressFilter}]{
579
+ 'all_lessons_count': count(*[brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}]._id),
580
+ 'lessons': *[brand == '${brand}' &amp;&amp; ^._id in ${groupBy}[]._ref ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}]{
546
581
  ${fieldsString},
547
582
  ${groupBy}
548
583
  }[0...10]
@@ -553,10 +588,10 @@ export async function fetchAll(brand, type, {
553
588
  } else {
554
589
  query = `
555
590
  {
556
- "entity": *[_type == '${type}' &amp;&amp; brand == "${brand}" ${searchFilter} ${includedFieldsFilter} ${progressFilter}] | order(${sortOrder}) [${start}...${end}] {
591
+ "entity": *[brand == "${brand}" ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}] | order(${sortOrder}) [${start}...${end}] {
557
592
  ${fieldsString},
558
593
  },
559
- "total": count(*[_type == '${type}' &amp;&amp; brand == "${brand}" ${searchFilter} ${includedFieldsFilter} ${progressFilter}])
594
+ "total": count(*[brand == "${brand}" ${typeFilter} ${searchFilter} ${includedFieldsFilter} ${progressFilter}])
560
595
  }
561
596
  `;
562
597
  }
@@ -664,8 +699,8 @@ export async function fetchChildren(railcontentId, contentType) {
664
699
  ${getFieldsForContentType(contentType)}
665
700
  },
666
701
  }[0..1]`;
667
- let parent = await fetchSanity(query, true);
668
- return parent[0]['children'] ?? [];
702
+ let parent = await fetchSanity(query, false);
703
+ return parent['children'] ?? [];
669
704
  }
670
705
 
671
706
  /**
@@ -681,8 +716,8 @@ export async function fetchParentByRailContentId(railcontentId) {
681
716
  })
682
717
  ])
683
718
  }[0...1]`;
684
- let child = await fetchSanity(query, true);
685
- return child[0]['parents'][0] ?? [];
719
+ let child = await fetchSanity(query, false);
720
+ return child['parents'][0] ?? [];
686
721
  }
687
722
 
688
723
  /**
@@ -703,9 +738,16 @@ export async function fetchMethods(brand) {
703
738
  * @returns {Promise&lt;Object|null>} - The fetched foundation data or null if not found.
704
739
  */
705
740
  export async function fetchFoundation(slug) {
706
- const query = `*[_type == 'foundation' &amp;&amp; slug.current == "${slug}"] {
707
- ${ getFieldsForContentType('foundation') }
708
- } | order(published_on asc)`
741
+ const filterParams = {};
742
+ const query = buildQuery(
743
+ `_type == 'foundation' &amp;&amp; slug.current == "${slug}"`,
744
+ filterParams,
745
+ getFieldsForContentType('foundation'),
746
+ {
747
+ sortOrder: 'published_on asc',
748
+ isSingle: true,
749
+ }
750
+ );
709
751
  return fetchSanity(query, false);
710
752
  }
711
753
 
@@ -808,7 +850,6 @@ export async function fetchMethodPreviousNextLesson(railcontentId, methodId) {
808
850
  * @returns {Promise&lt;Array&lt;Object>|null>} - The fetched children data or null if not found.
809
851
  */
810
852
  export async function fetchMethodChildrenIds(railcontentId) {
811
- //TODO: Implement getByParentId include sum XP
812
853
  const query = `*[_type == 'learning-path' &amp;&amp; railcontent_id == ${railcontentId}]{
813
854
  'children': child[]-> {
814
855
  'id': railcontent_id,
@@ -821,7 +862,7 @@ export async function fetchMethodChildrenIds(railcontentId) {
821
862
  }
822
863
  }`;
823
864
  let allChildren = await fetchSanity(query, false);
824
- return getChildrenToDepth(allChildren, 4);;
865
+ return getChildrenToDepth(allChildren, 4);
825
866
  }
826
867
 
827
868
  function getChildrenToDepth(parent, depth = 1)
@@ -870,8 +911,8 @@ export async function fetchNextPreviousLesson(railcontentId) {
870
911
  * .catch(error => console.error(error));
871
912
  */
872
913
  export async function fetchLessonContent(railContentId) {
873
- const query = `*[railcontent_id == ${railContentId} ]{
874
- title,
914
+ const filterParams = {};
915
+ const fields = `title,
875
916
  published_on,
876
917
  "type":_type,
877
918
  "resources": resource,
@@ -907,8 +948,19 @@ export async function fetchLessonContent(railContentId) {
907
948
  },
908
949
  ${assignmentsField}
909
950
  video,
910
- length_in_seconds
911
- }`
951
+ length_in_seconds,
952
+ mp3_no_drums_no_click_url,
953
+ mp3_no_drums_yes_click_url,
954
+ mp3_yes_drums_no_click_url,
955
+ mp3_yes_drums_yes_click_url,`;
956
+ const query = buildQuery(
957
+ `railcontent_id == ${railContentId}`,
958
+ filterParams,
959
+ fields,
960
+ {
961
+ isSingle: true,
962
+ }
963
+ );
912
964
  return fetchSanity(query, false);
913
965
  }
914
966
 
@@ -967,10 +1019,16 @@ export async function fetchRelatedMethodLessons(railContentId, brand) {
967
1019
  */
968
1020
  export async function fetchAllPacks(brand, sort = "-published_on", searchTerm = "") {
969
1021
  const sortOrder = getSortOrder(sort);
970
-
971
- const query = `*[_type == 'pack' &amp;&amp; brand == '${brand}' &amp;&amp; title match "${searchTerm}*"]{
972
- ${getFieldsForContentType('pack')}
973
- } | order(${sortOrder})`
1022
+ const filter = `_type == 'pack' &amp;&amp; brand == '${brand}' &amp;&amp; title match "${searchTerm}*"`
1023
+ const filterParams = {};
1024
+ const query = buildQuery(
1025
+ filter,
1026
+ filterParams,
1027
+ getFieldsForContentType('pack'),
1028
+ {
1029
+ sortOrder: sortOrder,
1030
+ }
1031
+ );
974
1032
  return fetchSanity(query, true);
975
1033
  }
976
1034
 
@@ -980,11 +1038,7 @@ export async function fetchAllPacks(brand, sort = "-published_on", searchTerm =
980
1038
  * @returns {Promise&lt;Array&lt;Object>|null>} - The fetched pack content data or null if not found.
981
1039
  */
982
1040
  export async function fetchPackAll(railcontentId) {
983
- //TODO: Implement getPacks
984
- const query = `*[railcontent_id == ${railcontentId}]{
985
- ${getFieldsForContentType('pack')}
986
- } | order(published_on asc)[0...1]`
987
- return fetchSanity(query, false);
1041
+ return fetchByRailContentId(railcontentId, 'pack');
988
1042
  }
989
1043
 
990
1044
  export async function fetchLiveEvent(brand) {
@@ -1060,7 +1114,7 @@ export async function fetchPackChildren(railcontentId) {
1060
1114
  export async function fetchChallengeOverview(id) {
1061
1115
  // WIP
1062
1116
  const query = `*[railcontent_id == ${id}]{
1063
- ${getFieldsForContentType("challenge", true)}
1117
+ ${getFieldsForContentType("challenge")}
1064
1118
  "lessons": child[]->{
1065
1119
  "id": railcontent_id,
1066
1120
  title,
@@ -1071,7 +1125,7 @@ export async function fetchChallengeOverview(id) {
1071
1125
  difficulty,
1072
1126
  "type": _type,
1073
1127
  }
1074
- }`;
1128
+ } [0...1]`;
1075
1129
  return fetchSanity(query, false);
1076
1130
  }
1077
1131
 
@@ -1091,18 +1145,21 @@ export async function fetchCoachLessons(brand, id, {
1091
1145
  page = 1,
1092
1146
  limit = 20,
1093
1147
  } = {}) {
1094
- const fieldsString = DEFAULT_FIELDS.join(',');
1148
+ const fieldsString = getFieldsForContentType();
1095
1149
  const start = (page - 1) * limit;
1096
1150
  const end = start + limit;
1097
- const searchFilter = searchTerm ? `&amp;&amp; title match "${searchTerm}*"`: ''
1098
-
1099
- const query = `{
1100
- "entity": *[brand == '${brand}' ${searchFilter} &amp;&amp; references(*[_type=='instructor' &amp;&amp; railcontent_id == ${id}]._id)] | order(${sortOrder}) [${start}...${end}]
1101
- {
1102
- ${fieldsString}
1103
- },
1104
- "total": count(*[brand == '${brand}' &amp;&amp; references(*[_type=='instructor' &amp;&amp; railcontent_id == ${id}]._id)])
1105
- }`;
1151
+ const searchFilter = searchTerm ? `&amp;&amp; title match "${searchTerm}*"`: ''
1152
+ const filter = `brand == '${brand}' ${searchFilter} &amp;&amp; references(*[_type=='instructor' &amp;&amp; railcontent_id == ${id}]._id)`;
1153
+ sortOrder = getSortOrder(sortOrder);
1154
+ const query = buildEntityAndTotalQuery(
1155
+ filter,
1156
+ fieldsString,
1157
+ {
1158
+ sortOrder: sortOrder,
1159
+ start: start,
1160
+ end: end,
1161
+ },
1162
+ );
1106
1163
  return fetchSanity(query, true);
1107
1164
  }
1108
1165
 
@@ -1117,10 +1174,7 @@ export async function fetchCoachLessons(brand, id, {
1117
1174
  * .catch(error => console.error(error));
1118
1175
  */
1119
1176
  export async function fetchCourseOverview(id) {
1120
- const query = `*[railcontent_id == ${id}]{
1121
- ${getFieldsForContentType("course", true)}
1122
- }`
1123
- return fetchSanity(query, false);
1177
+ return fetchByRailContentId(id, 'course');
1124
1178
  }
1125
1179
 
1126
1180
  /**
@@ -1141,21 +1195,23 @@ export async function fetchByReference(brand, {
1141
1195
  limit = 20,
1142
1196
  includedFields = [],
1143
1197
  } = {}) {
1144
- const fieldsString = DEFAULT_FIELDS.join(',');
1198
+ const fieldsString = getFieldsForContentType();
1145
1199
  const start = (page - 1) * limit;
1146
1200
  const end = start + limit;
1147
1201
  const searchFilter = searchTerm ? `&amp;&amp; title match "${searchTerm}*"`: '';
1148
1202
  const includedFieldsFilter = includedFields.length > 0
1149
1203
  ? includedFields.join(' &amp;&amp; ')
1150
1204
  : "";
1151
-
1152
- const query = `{
1153
- "entity": *[brand == '${brand}' ${searchFilter} &amp;&amp; references(*[${includedFieldsFilter}]._id)] | order(${sortOrder}) [${start}...${end}]
1154
- {
1155
- ${fieldsString}
1156
- },
1157
- "total": count(*[brand == '${brand}' &amp;&amp; references(*[${includedFieldsFilter}]._id)])
1158
- }`;
1205
+ const filter = `brand == '${brand}' ${searchFilter} &amp;&amp; references(*[${includedFieldsFilter}]._id)`;
1206
+ const query = buildEntityAndTotalQuery(
1207
+ filter,
1208
+ fieldsString,
1209
+ {
1210
+ sortOrder: getSortOrder(sortOrder),
1211
+ start: start,
1212
+ end: end,
1213
+ },
1214
+ );
1159
1215
  return fetchSanity(query, true);
1160
1216
  }
1161
1217
 
@@ -1320,6 +1376,48 @@ export async function fetchCatalogMetadata(contentType)
1320
1376
  return fetchSanity(query, false);
1321
1377
  }
1322
1378
 
1379
+ /**
1380
+ * Fetch shows data for a brand.
1381
+ *
1382
+ * @param brand - The brand for which to fetch shows.
1383
+ * @returns {Promise&lt;[]>}
1384
+ *
1385
+ * @example
1386
+ *
1387
+ * fetchShowsData('drumeo')
1388
+ * .then(data => console.log(data))
1389
+ * .catch(error => console.error(error));
1390
+ */
1391
+ export async function fetchShowsData(brand) {
1392
+ let shows = showsTypes[brand] ?? [];
1393
+ const showsInfo = [];
1394
+
1395
+ shows.forEach(type => {
1396
+ const processedData = processMetadata(brand, type);
1397
+ if (processedData) showsInfo.push(processedData)
1398
+ });
1399
+
1400
+ return showsInfo;
1401
+ }
1402
+
1403
+ /**
1404
+ * Fetch metadata from the contentTypeConfig.js based on brand and type.
1405
+ *
1406
+ * @param {string} brand - The brand for which to fetch metadata.
1407
+ * @param {string} type - The type for which to fetch metadata.
1408
+ * @returns {Promise&lt;{name, description, type: *, thumbnailUrl}>}
1409
+ *
1410
+ * @example
1411
+ *
1412
+ * fetchMetadata('drumeo','song')
1413
+ * .then(data => console.log(data))
1414
+ * .catch(error => console.error(error));
1415
+ */
1416
+ export async function fetchMetadata(brand, type) {
1417
+ const processedData = processMetadata(brand, type, true);
1418
+ return processedData ? processedData : {};
1419
+ }
1420
+
1323
1421
 
1324
1422
  //Helper Functions
1325
1423
  function arrayJoinWithQuotes(array, delimiter = ',') {
@@ -1359,6 +1457,129 @@ function checkSanityConfig(config) {
1359
1457
  }
1360
1458
 
1361
1459
 
1460
+ function buildRawQuery(
1461
+ filter = '',
1462
+ fields = '...',
1463
+ {
1464
+ sortOrder = 'published_on desc',
1465
+ start = 0,
1466
+ end = 10,
1467
+ isSingle = false,
1468
+ }
1469
+ ) {
1470
+ const sortString = sortOrder ? `order(${sortOrder})` : '';
1471
+ const countString = isSingle ? '[0...1]' : `[${start}...${end}]`;
1472
+ const query = `*[${filter}]{
1473
+ ${fields}
1474
+ } | ${sortString}${countString}`
1475
+ return query;
1476
+ }
1477
+
1478
+
1479
+ function buildQuery(
1480
+ baseFilter = '',
1481
+ filterParams = {},
1482
+ fields = '...',
1483
+ {
1484
+ sortOrder = 'published_on desc',
1485
+ start = 0,
1486
+ end = 10,
1487
+ isSingle = false,
1488
+ },
1489
+ ) {
1490
+ const filter = new FilterBuilder(baseFilter, filterParams).buildFilter();
1491
+ return buildRawQuery(filter, fields, {sortOrder, start, end, isSingle});
1492
+ }
1493
+
1494
+ function buildEntityAndTotalQuery(
1495
+ filter = '',
1496
+ fields = '...',
1497
+ {
1498
+ sortOrder = 'published_on desc',
1499
+ start = 0,
1500
+ end = 10,
1501
+ isSingle = false,
1502
+ },
1503
+ ) {
1504
+ const sortString = sortOrder ? `order(${sortOrder})` : '';
1505
+ const countString = isSingle ? '[0...1]' : `[${start}...${end}]`;
1506
+ const query = `{
1507
+ "entity": *[${filter}] | ${sortString}${countString}
1508
+ {
1509
+ ${fields}
1510
+ },
1511
+ "total": count(*[${filter}])
1512
+ }`;
1513
+ return query;
1514
+ }
1515
+ function processMetadata(brand, type, withFilters = false) {
1516
+ const metadataElement = contentMetadata[brand]?.[type];
1517
+ if (!metadataElement) {
1518
+ return null;
1519
+ }
1520
+
1521
+ const processedData = {
1522
+ type,
1523
+ thumbnailUrl: metadataElement.thumbnailUrl || null,
1524
+ name: metadataElement.name || null,
1525
+ description: metadataElement.description || null
1526
+ };
1527
+
1528
+ if (withFilters) {
1529
+ Object.keys(metadataElement).forEach(key => {
1530
+ if (key !== 'thumbnailUrl' &amp;&amp; key !== 'name' &amp;&amp; key !== 'description') {
1531
+ processedData[key] = metadataElement[key];
1532
+ }
1533
+ });
1534
+ // processedData.icon = metadataElement.icon || null;
1535
+ // processedData.sortBy = metadataElement.sortBy || null;
1536
+ // processedData.allowableFilters = metadataElement.allowableFilters || [];
1537
+ // processedData.tabs = metadataElement.tabs ? metadataElement.tabs.map(tab => ({
1538
+ // name: tab.name,
1539
+ // short_name: tab.short_name,
1540
+ // value: tab.value || null,
1541
+ // is_required_field: tab.is_required_field || false
1542
+ // })) : [];
1543
+ }
1544
+
1545
+ return processedData;
1546
+ }
1547
+ function processMetadatas(brand, type, withFilters=false) {
1548
+ const metadataElement = contentMetadata[brand]?.[type];
1549
+ if (!metadataElement) {
1550
+ return null;
1551
+ }
1552
+
1553
+ const processedData = {
1554
+ type,
1555
+ thumbnailUrl: metadataElement.thumbnailUrl || null,
1556
+ name: metadataElement.name || null,
1557
+ description: metadataElement.description || null
1558
+ };
1559
+
1560
+ if(withFilters){
1561
+ processedData.push({
1562
+ icon: metadataElement.icon || null,
1563
+ sortBy: metadataElement.sortBy || null,
1564
+ allowableFilters: metadataElement.allowableFilters || [],
1565
+ tabs: metadataElement.tabs ? metadataElement.tabs.map(tab => ({
1566
+ name: tab.name,
1567
+ short_name: tab.short_name,
1568
+ value: tab.value || null,
1569
+ is_required_field: tab.is_required_field || false
1570
+ })) : [],
1571
+
1572
+ });
1573
+ }
1574
+
1575
+ return processedData;
1576
+ }
1577
+
1578
+
1579
+
1580
+
1581
+
1582
+
1362
1583
  </code></pre>
1363
1584
  </article>
1364
1585
  </section>
@@ -1373,7 +1594,7 @@ function checkSanityConfig(config) {
1373
1594
  <br class="clear">
1374
1595
 
1375
1596
  <footer>
1376
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Thu Sep 19 2024 14:19:19 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1597
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Fri Sep 20 2024 13:45:33 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1377
1598
  </footer>
1378
1599
 
1379
1600
  <script>prettyPrint();</script>
File without changes
File without changes
File without changes
File without changes
File without changes