musora-content-services 1.0.57 → 1.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.59](https://github.com/railroadmedia/musora-content-services/compare/v1.0.58...v1.0.59) (2024-08-26)
6
+
7
+ ### [1.0.58](https://github.com/railroadmedia/musora-content-services/compare/v1.0.57...v1.0.58) (2024-08-26)
8
+
5
9
  ### [1.0.57](https://github.com/railroadmedia/musora-content-services/compare/v1.0.56...v1.0.57) (2024-08-26)
6
10
 
7
11
  ### [1.0.56](https://github.com/railroadmedia/musora-content-services/compare/v1.0.55...v1.0.56) (2024-08-26)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.57",
3
+ "version": "1.0.59",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -6,6 +6,18 @@ import {globalConfig} from "./config";
6
6
 
7
7
  import { fetchAllCompletedStates, fetchCurrentSongComplete } from './railcontent.js';
8
8
 
9
+ const DEFAULT_FIELDS = [
10
+ '"id": railcontent_id',
11
+ 'railcontent_id',
12
+ '"type": _type',
13
+ 'title',
14
+ '"image": thumbnail.asset->url',
15
+ 'difficulty',
16
+ 'difficulty_string',
17
+ 'web_url_path',
18
+ 'published_on'
19
+ ];
20
+
9
21
  /**
10
22
  * Fetch a song by its document ID from Sanity.
11
23
  *
@@ -363,6 +375,7 @@ export async function fetchByRailContentId(id) {
363
375
  * Fetch content by an array of Railcontent IDs.
364
376
  *
365
377
  * @param {Array<string>} ids - The array of Railcontent IDs of the content to fetch.
378
+ * @param {string} [contentType] - The content type the IDs to add needed fields to the response.
366
379
  * @returns {Promise<Array<Object>|null>} - A promise that resolves to an array of content objects or null if not found.
367
380
  *
368
381
  * @example
@@ -370,18 +383,11 @@ export async function fetchByRailContentId(id) {
370
383
  * .then(contents => console.log(contents))
371
384
  * .catch(error => console.error(error));
372
385
  */
373
- export async function fetchByRailContentIds(ids) {
386
+ export async function fetchByRailContentIds(ids, contentType = undefined) {
387
+ const fields = contentType ? DEFAULT_FIELDS.concat(contentTypeConfig?.[contentType]?.fields ?? []) : DEFAULT_FIELDS;
374
388
  const idsString = ids.join(',');
375
389
  const query = `*[railcontent_id in [${idsString}]]{
376
- railcontent_id,
377
- title,
378
- "image": thumbnail.asset->url,
379
- "artist_name": artist->name,
380
- artist,
381
- difficulty,
382
- difficulty_string,
383
- web_url_path,
384
- published_on
390
+ ${fields.join(', ')}
385
391
  }`
386
392
  return fetchSanity(query, true);
387
393
  }
@@ -474,19 +480,7 @@ export async function fetchAll(brand, type, {
474
480
  break;
475
481
  }
476
482
 
477
- let defaultFields = [
478
- '"id": railcontent_id',
479
- 'railcontent_id',
480
- '"type": _type',
481
- 'title',
482
- '"image": thumbnail.asset->url',
483
- 'difficulty',
484
- 'difficulty_string',
485
- 'web_url_path',
486
- 'published_on'
487
- ];
488
-
489
- let fields = defaultFields.concat(additionalFields);
483
+ let fields = DEFAULT_FIELDS.concat(additionalFields);
490
484
  let fieldsString = fields.join(',');
491
485
 
492
486
  // Determine the group by clause
@@ -649,7 +643,7 @@ export async function fetchMethods(brand) {
649
643
  length_in_seconds,
650
644
  permission,
651
645
  popularity,
652
- "position": count(*[_type == 'learning-path' && brand == 'drumeo' && (published_on < ^.published_on || (published_on == ^.published_on && _id < ^._id))]) + 1,
646
+ "position": count(*[_type == 'learning-path' && brand == '${brand}' && (published_on < ^.published_on || (published_on == ^.published_on && _id < ^._id))]) + 1,
653
647
  published_on,
654
648
  railcontent_id,
655
649
  "slug": slug.current,
@@ -658,7 +652,7 @@ export async function fetchMethods(brand) {
658
652
  title,
659
653
  total_xp,
660
654
  "type": _type,
661
- web_url_path,
655
+ "url": web_url_path,
662
656
  xp
663
657
  }`
664
658
  return fetchSanity(query, true);