musora-content-services 1.0.194 → 1.0.196

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.196](https://github.com/railroadmedia/musora-content-services/compare/v1.0.195...v1.0.196) (2024-11-29)
6
+
7
+ ### [1.0.195](https://github.com/railroadmedia/musora-content-services/compare/v1.0.194...v1.0.195) (2024-11-29)
8
+
5
9
  ### [1.0.194](https://github.com/railroadmedia/musora-content-services/compare/v1.0.193...v1.0.194) (2024-11-29)
6
10
 
7
11
  ### [1.0.193](https://github.com/railroadmedia/musora-content-services/compare/v1.0.192...v1.0.193) (2024-11-28)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.194",
3
+ "version": "1.0.196",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -21,6 +21,7 @@ const excludeFromGeneratedIndex = [
21
21
  'fetchUserPermissionsData'
22
22
  ];
23
23
 
24
+ let challengeIndexMetaDataPromise = null;
24
25
 
25
26
  /**
26
27
  * Fetches the completion status of a specific lesson for the current user.
@@ -396,11 +397,24 @@ export async function fetchUserAward(contentId) {
396
397
  * @returns {Promise<any|null>}
397
398
  */
398
399
  export async function fetchChallengeIndexMetadata(contentIds) {
399
- let idsString = contentIds.toString();
400
- let url = `/challenges/user_progress_for_index_page/get?content_ids=${idsString}`;
401
- return await fetchHandler(url, 'get');
400
+ if (!challengeIndexMetaDataPromise) {
401
+ challengeIndexMetaDataPromise = getChallengeIndexMetadataPromise();
402
+ }
403
+ let results = await challengeIndexMetaDataPromise;
404
+ results = results.filter(function(challenge){
405
+ return contentIds.includes(challenge.content_id);
406
+ });
407
+ return results;
402
408
  }
403
409
 
410
+ async function getChallengeIndexMetadataPromise() {
411
+ let url = `/challenges/user_progress_for_index_page/get`;
412
+ const result = await fetchHandler(url, 'get');
413
+ challengeIndexMetaDataPromise = null;
414
+ return result;
415
+ }
416
+
417
+
404
418
  /**
405
419
  * Get active brand challenges for the authorized user
406
420
  *
@@ -752,9 +752,11 @@ export function getSortOrder(sort = '-published_on', groupBy) {
752
752
  sortOrder = groupBy ? 'name' : "title";
753
753
  break;
754
754
  case "name":
755
- case "popularity":
756
755
  sortOrder = sort;
757
756
  break;
757
+ case "popularity":
758
+ sortOrder = isDesc ? "coalesce(popularity, -1)" : "popularity";
759
+ break;
758
760
  case "published_on":
759
761
  default:
760
762
  sortOrder = "published_on";
@@ -109,7 +109,6 @@ describe('contentProgressDataContextLocal', function () {
109
109
 
110
110
  }, 100000);
111
111
 
112
-
113
112
  //
114
113
  // test('progressBubbling', async () => {
115
114
  // let serverVersion = 2;
@@ -0,0 +1,16 @@
1
+ import {initializeTestService} from "../initializeTests";
2
+ import {fetchChallengeIndexMetadata} from "../../src";
3
+
4
+
5
+ describe('railcontentLive', function () {
6
+ beforeEach(async () => {
7
+ await initializeTestService(true);
8
+ }, 1000000);
9
+
10
+ test('challengeIndexMetadata', async () => {
11
+ let contentId = 281709;
12
+ let results = await fetchChallengeIndexMetadata([contentId]);
13
+ expect(Array.isArray(results)).toBe(true);
14
+ });
15
+
16
+ });