musora-content-services 1.0.176 → 1.0.178

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.178](https://github.com/railroadmedia/musora-content-services/compare/v1.0.177...v1.0.178) (2024-11-19)
6
+
7
+ ### [1.0.177](https://github.com/railroadmedia/musora-content-services/compare/v1.0.176...v1.0.177) (2024-11-18)
8
+
5
9
  ### [1.0.176](https://github.com/railroadmedia/musora-content-services/compare/v1.0.161...v1.0.176) (2024-11-15)
6
10
 
7
11
  ### [1.0.175](https://github.com/railroadmedia/musora-content-services/compare/v1.0.174...v1.0.175) (2024-11-15)
package/README.md CHANGED
File without changes
package/jest.config.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.176",
3
+ "version": "1.0.178",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -37,13 +37,11 @@ const commonMetadata ={
37
37
  {
38
38
  name: 'Completed',
39
39
  short_name: 'COMPLETED',
40
- is_group_by: true,
41
40
  value: 'completed'
42
41
  },
43
42
  {
44
43
  name: 'Owned Challenges',
45
44
  short_name: 'OWNED CHALLENGES',
46
- is_group_by: true,
47
45
  value: 'owned',
48
46
  },
49
47
  ],
File without changes
package/src/index.d.ts CHANGED
@@ -40,12 +40,14 @@ import {
40
40
  fetchChallengeLessonData,
41
41
  fetchChallengeMetadata,
42
42
  fetchChallengeUserActiveChallenges,
43
+ fetchCompletedChallenges,
43
44
  fetchCompletedContent,
44
45
  fetchCompletedState,
45
46
  fetchContentInProgress,
46
47
  fetchContentPageUserData,
47
48
  fetchContentProgress,
48
49
  fetchHandler,
50
+ fetchOwnedChallenges,
49
51
  fetchPinnedPlaylists,
50
52
  fetchPlaylist,
51
53
  fetchPlaylistItem,
@@ -166,6 +168,7 @@ declare module 'musora-content-services' {
166
168
  fetchChildren,
167
169
  fetchCoachLessons,
168
170
  fetchCommentModContentData,
171
+ fetchCompletedChallenges,
169
172
  fetchCompletedContent,
170
173
  fetchCompletedState,
171
174
  fetchContentInProgress,
@@ -187,6 +190,7 @@ declare module 'musora-content-services' {
187
190
  fetchMethods,
188
191
  fetchNewReleases,
189
192
  fetchNextPreviousLesson,
193
+ fetchOwnedChallenges,
190
194
  fetchPackAll,
191
195
  fetchPackChildren,
192
196
  fetchPackData,
package/src/index.js CHANGED
@@ -40,12 +40,14 @@ import {
40
40
  fetchChallengeLessonData,
41
41
  fetchChallengeMetadata,
42
42
  fetchChallengeUserActiveChallenges,
43
+ fetchCompletedChallenges,
43
44
  fetchCompletedContent,
44
45
  fetchCompletedState,
45
46
  fetchContentInProgress,
46
47
  fetchContentPageUserData,
47
48
  fetchContentProgress,
48
49
  fetchHandler,
50
+ fetchOwnedChallenges,
49
51
  fetchPinnedPlaylists,
50
52
  fetchPlaylist,
51
53
  fetchPlaylistItem,
@@ -165,6 +167,7 @@ export {
165
167
  fetchChildren,
166
168
  fetchCoachLessons,
167
169
  fetchCommentModContentData,
170
+ fetchCompletedChallenges,
168
171
  fetchCompletedContent,
169
172
  fetchCompletedState,
170
173
  fetchContentInProgress,
@@ -186,6 +189,7 @@ export {
186
189
  fetchMethods,
187
190
  fetchNewReleases,
188
191
  fetchNextPreviousLesson,
192
+ fetchOwnedChallenges,
189
193
  fetchPackAll,
190
194
  fetchPackChildren,
191
195
  fetchPackData,
File without changes
File without changes
File without changes
File without changes
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @module Railcontent-Services
3
3
  */
4
+ import {contentStatusCompleted} from "./contentProgress";
4
5
 
5
6
  const {globalConfig} = require('./config');
6
7
 
@@ -335,6 +336,36 @@ export async function fetchChallengeLessonData(contentId) {
335
336
  return await fetchHandler(url, 'get');
336
337
  }
337
338
 
339
+
340
+ /**
341
+ * Fetch all owned brand challenges for user
342
+ * @param {string|null} brand - brand
343
+ * @param {int} page - page of data to pull
344
+ * @param {int} limit - number of elements to pull
345
+ * @returns {Promise<any|null>}
346
+ */
347
+ export async function fetchOwnedChallenges(brand = null, page, limit) {
348
+ let brandParam = brand ? `&brand=${brand}` : '';
349
+ let pageAndLimit = `?page=${page}&limit=${limit}`;
350
+ let url = `/challenges/tab_owned/get${pageAndLimit}${brandParam}`;
351
+ return await fetchHandler(url, 'get');
352
+ }
353
+
354
+ /**
355
+ * Fetch all completed brand challenges for user
356
+ * @param {string|null} brand - brand
357
+ * @param {int} page - page of data to pull
358
+ * @param {int} limit - number of elements to pull
359
+ * @returns {Promise<any|null>}
360
+ */
361
+ export async function fetchCompletedChallenges(brand = null, page, limit) {
362
+ let brandParam = brand ? `&brand=${brand}` : '';
363
+ let pageAndLimit = `?page=${page}&limit=${limit}`;
364
+ let url = `/challenges/tab_completed/get${pageAndLimit}${brandParam}`;
365
+ return await fetchHandler(url, 'get');
366
+ }
367
+
368
+
338
369
  /**
339
370
  * Fetch challenge, lesson, and user metadata for a given challenge
340
371
  *
@@ -472,6 +503,7 @@ export async function postChallengesCommunityNotification(contentId) {
472
503
  */
473
504
  export async function postChallengesCompleteLesson(contentId) {
474
505
  let url = `/challenges/complete_lesson/${contentId}`;
506
+ await contentStatusCompleted(contentId);
475
507
  return await fetchHandler(url, 'post');
476
508
  }
477
509
 
@@ -23,7 +23,12 @@ import {
23
23
 
24
24
  import {globalConfig} from "./config";
25
25
 
26
- import {fetchAllCompletedStates, fetchCurrentSongComplete} from './railcontent.js';
26
+ import {
27
+ fetchAllCompletedStates,
28
+ fetchCompletedChallenges,
29
+ fetchCurrentSongComplete,
30
+ fetchOwnedChallenges
31
+ } from './railcontent.js';
27
32
  import {arrayToStringRepresentation, FilterBuilder} from "../filterBuilder";
28
33
  import {fetchUserPermissions} from "./userPermissions";
29
34
  import {getAllCompleted, getAllStarted, getAllStartedOrCompleted} from "./contentProgress";
@@ -33,7 +38,7 @@ import {getAllCompleted, getAllStarted, getAllStartedOrCompleted} from "./conten
33
38
  *
34
39
  * @type {string[]}
35
40
  */
36
- const excludeFromGeneratedIndex = [];
41
+ const excludeFromGeneratedIndex = ['handleCustomFetchAll'];
37
42
 
38
43
  /**
39
44
  * Fetch a song by its document ID from Sanity.
@@ -484,6 +489,21 @@ export async function fetchAll(brand, type, {
484
489
  customFields = [],
485
490
  progress = "all"
486
491
  } = {}) {
492
+ let customResults = await handleCustomFetchAll(brand, type, {
493
+ page,
494
+ limit,
495
+ searchTerm,
496
+ sort,
497
+ includedFields,
498
+ groupBy,
499
+ progressIds,
500
+ useDefaultFields,
501
+ customFields,
502
+ progress});
503
+ if (customResults) {
504
+ return customResults;
505
+ }
506
+
487
507
  let config = contentTypeConfig[type] ?? {};
488
508
  let additionalFields = config?.fields ?? [];
489
509
  let isGroupByOneToOne = (groupBy ? config?.relationships?.[groupBy]?.isOneToOne : false) ?? false;
@@ -566,6 +586,45 @@ export async function fetchAll(brand, type, {
566
586
  return fetchSanity(query, true);
567
587
  }
568
588
 
589
+ /**
590
+ * Fetch all content that requires custom handling or a distinct external call
591
+ * @param {string} brand - The brand for which to fetch content.
592
+ * @param {string} type - The content type to fetch (e.g., 'song', 'artist').
593
+ * @param {Object} params - Parameters for pagination, filtering, sorting, and grouping.
594
+ * @param {number} [params.page=1] - The page number for pagination.
595
+ * @param {number} [params.limit=10] - The number of items per page.
596
+ * @param {string} [params.searchTerm=""] - The search term to filter content by title or artist.
597
+ * @param {string} [params.sort="-published_on"] - The field to sort the content by.
598
+ * @param {Array<string>} [params.includedFields=[]] - The fields to include in the query.
599
+ * @param {string} [params.groupBy=""] - The field to group the results by (e.g., 'artist', 'genre').
600
+ * @param {Array<string>} [params.progressIds=undefined] - An array of railcontent IDs to filter the results by. Used for filtering by progress.
601
+ * @param {boolean} [params.useDefaultFields=true] - use the default sanity fields for content Type
602
+ * @param {Array<string>} [params.customFields=[]] - An array of sanity fields to include in the request
603
+ * @param {string} [params.progress="all"] - An string representing which progress filter to use ("all", "in progress", "complete", "not started").
604
+ * @returns {Promise<Object|null>} - The fetched content data or null if not found.
605
+ */
606
+ async function handleCustomFetchAll(brand, type, {
607
+ page = 1,
608
+ limit = 10,
609
+ searchTerm = "",
610
+ sort = "-published_on",
611
+ includedFields = [],
612
+ groupBy = "",
613
+ progressIds = undefined,
614
+ useDefaultFields = true,
615
+ customFields = [],
616
+ progress = "all"
617
+ } = {}) {
618
+ if (type === 'challenge') {
619
+ if (groupBy === 'completed') {
620
+ return fetchCompletedChallenges(brand, page, limit);
621
+ } else if(groupBy === 'owned') {
622
+ return fetchOwnedChallenges(brand, page, limit);
623
+ }
624
+ }
625
+ return null;
626
+ }
627
+
569
628
  async function getProgressFilter(progress, progressIds) {
570
629
  switch (progress) {
571
630
  case "all":
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/test/log.js CHANGED
File without changes
File without changes
File without changes