musora-content-services 1.0.86 → 1.0.87

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,8 @@
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.87](https://github.com/railroadmedia/musora-content-services/compare/v1.0.86...v1.0.87) (2024-09-09)
6
+
5
7
  ### [1.0.86](https://github.com/railroadmedia/musora-content-services/compare/v1.0.85...v1.0.86) (2024-09-09)
6
8
 
7
9
  ### [1.0.85](https://github.com/railroadmedia/musora-content-services/compare/v1.0.84...v1.0.85) (2024-09-06)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.86",
3
+ "version": "1.0.87",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -34,6 +34,7 @@ import {
34
34
  fetchLiveEvent,
35
35
  fetchChallengeOverview,
36
36
  fetchCoachLessons,
37
+ fetchByReference,
37
38
  } from './services/sanity.js';
38
39
 
39
40
  import {
@@ -85,4 +86,5 @@ export {
85
86
  fetchVimeoData,
86
87
  fetchContentPageUserData,
87
88
  fetchCoachLessons,
89
+ fetchByReference,
88
90
  }
@@ -820,37 +820,24 @@ export async function fetchLessonContent(railContentId) {
820
820
  * Fetch related lessons for a specific lesson by RailContent ID and type.
821
821
  * @param {string} railContentId - The RailContent ID of the current lesson.
822
822
  * @param {string} brand - The current brand.
823
- * @param {string} contentType - name of the contentype to pull
824
823
  * @returns {Promise<Array<Object>|null>} - The fetched related lessons data or null if not found.
825
824
  */
826
- export async function fetchRelatedLessons(railContentId, brand, contentType) {
827
- let typeQuery = contentType ? `_type=="${contentType}" &&` : "";
828
-
825
+ export async function fetchRelatedLessons(railContentId, brand) {
826
+ // let sort = 'published_on'
827
+ // if (type == 'rhythmic-adventures-of-captain-carson' ||
828
+ // type == 'diy-drum-experiments' ||
829
+ // type == 'in-rhythm') {
830
+ // sort = 'sort';
831
+ // }
829
832
  //TODO: Implement $this->contentService->getFiltered
830
833
  const query = `*[railcontent_id == ${railContentId} && brand == "${brand}" && references(*[_type=='permission']._id)]{
831
834
  "related_lessons" : array::unique([
832
- _...(*[${typeQuery} brand == "${brand}" && references(^.artist->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11]),
833
- ...(*[${typeQuery} brand == "${brand}" && references(^.genre[]->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11])
835
+ ...(*[_type=="song" && brand == "${brand}" && references(^.artist->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11]),
836
+ ...(*[_type=="song" && brand == "${brand}" && references(^.genre[]->_id)]{_id, "id":railcontent_id, published_on, title, "thumbnail_url":thumbnail.asset->url, difficulty_string, railcontent_id, artist->}[0...11])
834
837
  ])|order(published_on, railcontent_id)[0...11]}`;
835
838
  return fetchSanity(query, false);
836
839
  }
837
840
 
838
- /**
839
- * Fetch all packs.
840
- * @param {string} brand - The brand for which to fetch packs.
841
- * @param {string} [searchTerm=""] - The search term to filter packs.
842
- * @param {string} [sort="-published_on"] - The field to sort the packs by.
843
- * @returns {Promise<Array<Object>|null>} - The fetched pack content data or null if not found.
844
- */
845
- export async function fetchAllPacks(brand, sort = "-published_on", searchTerm = "") {
846
- const sortOrder = getSortOrder(sort);
847
-
848
- const query = `*[_type == 'pack' && brand == '${brand}' && title match "${searchTerm}*"]{
849
- ${getFieldsForContentType('pack')}
850
- } | order(${sortOrder})`
851
- return fetchSanity(query, true);
852
- }
853
-
854
841
  /**
855
842
  * Fetch all content for a specific pack by Railcontent ID.
856
843
  * @param {string} railcontentId - The Railcontent ID of the pack.
@@ -859,9 +846,18 @@ export async function fetchAllPacks(brand, sort = "-published_on", searchTerm =
859
846
  export async function fetchPackAll(railcontentId) {
860
847
  //TODO: Implement getPacks
861
848
  const query = `*[railcontent_id == ${railcontentId}]{
862
- ${getFieldsForContentType('pack')}
863
- } | order(published_on asc)[0...1]`
864
- return fetchSanity(query, false);
849
+ railcontent_id,
850
+ "id": railcontent_id,
851
+ title,
852
+ "image": thumbnail.asset->url,
853
+ "artist_name": artist->name,
854
+ artist,
855
+ difficulty,
856
+ difficulty_string,
857
+ web_url_path,
858
+ published_on
859
+ } | order(published_on asc)[0...5]`
860
+ return fetchSanity(query, true);
865
861
  }
866
862
 
867
863
  export async function fetchLiveEvent(brand) {
@@ -1021,6 +1017,43 @@ export async function fetchCourseOverview(id) {
1021
1017
  return fetchSanity(query, false);
1022
1018
  }
1023
1019
 
1020
+ /**
1021
+ * Fetch the data needed for the coach screen.
1022
+ * @param {string} id - The Railcontent ID of the coach
1023
+ *
1024
+ * @returns {Promise<Object|null>} - The lessons for the instructor or null if not found.
1025
+ *
1026
+ * @example
1027
+ * fetchCoachLessons('coach123')
1028
+ * .then(lessons => console.log(lessons))
1029
+ * .catch(error => console.error(error));
1030
+ */
1031
+ export async function fetchByReference(brand, {
1032
+ sortOrder = '-published_on',
1033
+ searchTerm = '',
1034
+ page = 1,
1035
+ limit = 20,
1036
+ includedFields = [],
1037
+ } = {}) {
1038
+ const fieldsString = DEFAULT_FIELDS.join(',');
1039
+ const start = (page - 1) * limit;
1040
+ const end = start + limit;
1041
+ const searchFilter = searchTerm ? `&& title match "${searchTerm}*"`: '';
1042
+ const includedFieldsFilter = includedFields.length > 0
1043
+ ? includedFields.join(' && ')
1044
+ : "";
1045
+
1046
+ const query = `{
1047
+ "entity": *[brand == '${brand}' ${searchFilter} && references(*[${includedFieldsFilter}]._id)] | order(${sortOrder}) [${start}...${end}]
1048
+ {
1049
+ ${fieldsString}
1050
+ },
1051
+ "total": count(*[brand == '${brand}' && references(*[${includedFieldsFilter}]._id)])
1052
+ }`;
1053
+ return fetchSanity(query, true);
1054
+ }
1055
+
1056
+
1024
1057
  /**
1025
1058
  * Fetch data from the Sanity API based on a provided query.
1026
1059
  *
@@ -31,6 +31,7 @@ const {
31
31
  fetchAllPacks,
32
32
  fetchPacksAll,
33
33
  fetchCoachLessons,
34
+ fetchByReference,
34
35
  } = require('../src/services/sanity.js');
35
36
 
36
37
  describe('Sanity Queries', function () {
@@ -158,7 +159,7 @@ describe('Sanity Queries', function () {
158
159
  const id = 380094;
159
160
  const document = await fetchByRailContentId(id);
160
161
  let artist = document.artist.name;
161
- const response = await fetchRelatedLessons(id, 'singeo', 'song');
162
+ const response = await fetchRelatedLessons(id, 'singeo');
162
163
  let relatedDoc = await fetchByRailContentId(response.related_lessons[0].id);
163
164
  // match on artist or any genre
164
165
  let isMatch = artist === relatedDoc.artist.name;
@@ -270,6 +271,7 @@ describe('Sanity Queries', function () {
270
271
  response = await fetchAllPacks('drumeo', 'slug', 'Creative Control');
271
272
  expect(response[0].id).toBe(212899);
272
273
  });
274
+
273
275
  test('fetchCoachLessons', async () => {
274
276
  const response = await fetchCoachLessons('drumeo',233797);
275
277
  expect(response.entity.length).toBeGreaterThan(0);
@@ -277,6 +279,11 @@ describe('Sanity Queries', function () {
277
279
 
278
280
  test('fetchAll-IncludedFields', async () => {
279
281
  let response = await fetchAll('drumeo', 'instructor',{includedFields: ['is_active']});
280
- console.log('---------------------------------------',response);
282
+ expect(response.entity.length).toBeGreaterThan(0);
283
+ });
284
+
285
+ test('fetchByReference', async () => {
286
+ const response = await fetchByReference('drumeo', { includedFields: ['is_featured'] });
287
+ expect(response.entity.length).toBeGreaterThan(0);
281
288
  });
282
289
  });