musora-content-services 1.0.173 → 1.0.175
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 +4 -0
- package/docs/config.js.html +4 -3
- package/docs/index.html +2 -2
- package/docs/module-Config.html +28 -4
- package/docs/module-Railcontent-Services.html +340 -79
- package/docs/module-Sanity-Services.html +403 -47
- package/docs/railcontent.js.html +58 -48
- package/docs/sanity.js.html +650 -560
- package/package.json +1 -1
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/services/contentProgress.js +19 -0
- package/src/services/sanity.js +26 -2
- package/test/contentProgress.test.js +11 -1
- package/test/sanityQueryService.test.js +30 -0
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
contentStatusReset,
|
|
19
19
|
getAllCompleted,
|
|
20
20
|
getAllStarted,
|
|
21
|
+
getAllStartedOrCompleted,
|
|
21
22
|
getProgressPercentage,
|
|
22
23
|
getProgressPercentageByIds,
|
|
23
24
|
getProgressState,
|
|
@@ -214,6 +215,7 @@ declare module 'musora-content-services' {
|
|
|
214
215
|
fetchWorkouts,
|
|
215
216
|
getAllCompleted,
|
|
216
217
|
getAllStarted,
|
|
218
|
+
getAllStartedOrCompleted,
|
|
217
219
|
getProgressPercentage,
|
|
218
220
|
getProgressPercentageByIds,
|
|
219
221
|
getProgressState,
|
package/src/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
contentStatusReset,
|
|
19
19
|
getAllCompleted,
|
|
20
20
|
getAllStarted,
|
|
21
|
+
getAllStartedOrCompleted,
|
|
21
22
|
getProgressPercentage,
|
|
22
23
|
getProgressPercentageByIds,
|
|
23
24
|
getProgressState,
|
|
@@ -213,6 +214,7 @@ export {
|
|
|
213
214
|
fetchWorkouts,
|
|
214
215
|
getAllCompleted,
|
|
215
216
|
getAllStarted,
|
|
217
|
+
getAllStartedOrCompleted,
|
|
216
218
|
getProgressPercentage,
|
|
217
219
|
getProgressPercentageByIds,
|
|
218
220
|
getProgressState,
|
|
@@ -81,6 +81,25 @@ export async function getAllCompleted(limit = null) {
|
|
|
81
81
|
return ids;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
export async function getAllStartedOrCompleted(limit = null) {
|
|
85
|
+
const data = await dataContext.getData();
|
|
86
|
+
let ids = Object.keys(data).filter(function (key) {
|
|
87
|
+
return data[parseInt(key)][DATA_KEY_STATUS] === STATE_STARTED || data[parseInt(key)][DATA_KEY_STATUS] === STATE_COMPLETED;
|
|
88
|
+
}).map(function (key) {
|
|
89
|
+
return parseInt(key);
|
|
90
|
+
}).sort(function (a, b) {
|
|
91
|
+
let v1 = data[a][DATA_KEY_LAST_UPDATED_TIME];
|
|
92
|
+
let v2 = data[b][DATA_KEY_LAST_UPDATED_TIME];
|
|
93
|
+
if (v1 > v2) return -1;
|
|
94
|
+
else if (v1 < v2) return 1;
|
|
95
|
+
return 0;
|
|
96
|
+
});
|
|
97
|
+
if (limit) {
|
|
98
|
+
ids = ids.slice(0, limit);
|
|
99
|
+
}
|
|
100
|
+
return ids;
|
|
101
|
+
}
|
|
102
|
+
|
|
84
103
|
export async function getResumeTimeSeconds(contentId) {
|
|
85
104
|
let data = await dataContext.getData();
|
|
86
105
|
return data[contentId]?.[DATA_KEY_RESUME_TIME] ?? 0;
|
package/src/services/sanity.js
CHANGED
|
@@ -26,6 +26,7 @@ import {globalConfig} from "./config";
|
|
|
26
26
|
import {fetchAllCompletedStates, fetchCurrentSongComplete} from './railcontent.js';
|
|
27
27
|
import {arrayToStringRepresentation, FilterBuilder} from "../filterBuilder";
|
|
28
28
|
import {fetchUserPermissions} from "./userPermissions";
|
|
29
|
+
import {getAllCompleted, getAllStarted, getAllStartedOrCompleted} from "./contentProgress";
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Exported functions that are excluded from index generation.
|
|
@@ -453,6 +454,7 @@ export async function fetchByRailContentIds(ids, contentType = undefined) {
|
|
|
453
454
|
* @param {Array<string>} [params.progressIds=undefined] - An array of railcontent IDs to filter the results by. Used for filtering by progress.
|
|
454
455
|
* @param {boolean} [params.useDefaultFields=true] - use the default sanity fields for content Type
|
|
455
456
|
* @param {Array<string>} [params.customFields=[]] - An array of sanity fields to include in the request
|
|
457
|
+
* @param {string} [params.progress="all"] - An string representing which progress filter to use ("all", "in progress", "complete", "not started").
|
|
456
458
|
* @returns {Promise<Object|null>} - The fetched content data or null if not found.
|
|
457
459
|
*
|
|
458
460
|
* @example
|
|
@@ -480,6 +482,7 @@ export async function fetchAll(brand, type, {
|
|
|
480
482
|
progressIds = undefined,
|
|
481
483
|
useDefaultFields = true,
|
|
482
484
|
customFields = [],
|
|
485
|
+
progress = "all"
|
|
483
486
|
} = {}) {
|
|
484
487
|
let config = contentTypeConfig[type] ?? {};
|
|
485
488
|
let additionalFields = config?.fields ?? [];
|
|
@@ -504,8 +507,7 @@ export async function fetchAll(brand, type, {
|
|
|
504
507
|
: "";
|
|
505
508
|
|
|
506
509
|
// limits the results to supplied progressIds for started & completed filters
|
|
507
|
-
const progressFilter =
|
|
508
|
-
`&& railcontent_id in [${progressIds.join(',')}]` : "";
|
|
510
|
+
const progressFilter = await getProgressFilter(progress, progressIds);
|
|
509
511
|
|
|
510
512
|
// Determine the sort order
|
|
511
513
|
const sortOrder = getSortOrder(sort);
|
|
@@ -564,6 +566,28 @@ export async function fetchAll(brand, type, {
|
|
|
564
566
|
return fetchSanity(query, true);
|
|
565
567
|
}
|
|
566
568
|
|
|
569
|
+
async function getProgressFilter(progress, progressIds) {
|
|
570
|
+
switch (progress) {
|
|
571
|
+
case "all":
|
|
572
|
+
return progressIds !== undefined ?
|
|
573
|
+
`&& railcontent_id in [${progressIds.join(',')}]` : "";
|
|
574
|
+
case "in progress": {
|
|
575
|
+
const ids = await getAllStarted();
|
|
576
|
+
return `&& railcontent_id in [${ids.join(',')}]`;
|
|
577
|
+
}
|
|
578
|
+
case "completed": {
|
|
579
|
+
const ids = await getAllCompleted();
|
|
580
|
+
return `&& railcontent_id in [${ids.join(',')}]`;
|
|
581
|
+
}
|
|
582
|
+
case "not started": {
|
|
583
|
+
const ids = await getAllStartedOrCompleted();
|
|
584
|
+
return `&& !(railcontent_id in [${ids.join(',')}])`;
|
|
585
|
+
}
|
|
586
|
+
default:
|
|
587
|
+
throw new Error(`'${progress}' progress option not implemented`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
567
591
|
export function getSortOrder(sort = '-published_on', groupBy) {
|
|
568
592
|
// Determine the sort order
|
|
569
593
|
let sortOrder = '';
|
|
@@ -7,7 +7,11 @@ import {
|
|
|
7
7
|
getProgressStateByIds,
|
|
8
8
|
getAllStarted,
|
|
9
9
|
getAllCompleted,
|
|
10
|
-
contentStatusCompleted,
|
|
10
|
+
contentStatusCompleted,
|
|
11
|
+
assignmentStatusCompleted,
|
|
12
|
+
contentStatusReset,
|
|
13
|
+
assignmentStatusReset,
|
|
14
|
+
getAllStartedOrCompleted
|
|
11
15
|
} from "../src/services/contentProgress";
|
|
12
16
|
import {initializeTestService} from "./initializeTests";
|
|
13
17
|
import {postContentCompleted} from "../src";
|
|
@@ -71,6 +75,12 @@ describe('contentProgressDataContext', function () {
|
|
|
71
75
|
expect(result).toStrictEqual([233955]);
|
|
72
76
|
});
|
|
73
77
|
|
|
78
|
+
test('getAllStartedOrCompleted', async () => {
|
|
79
|
+
let result = await getAllStartedOrCompleted();
|
|
80
|
+
expect(result).toStrictEqual([259426, 233955, 234191]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
|
|
74
84
|
// test('getAllStartedWithUpdate', async () => {
|
|
75
85
|
// let mock2 = jest.spyOn(railContentModule, 'postRecordWatchSession');
|
|
76
86
|
// let serverVersion = 2;
|
|
@@ -2,6 +2,7 @@ import {getFieldsForContentType} from "../src/contentTypeConfig";
|
|
|
2
2
|
import {fetchAssignments, fetchCommentModContentData, fetchSanity} from "../src/services/sanity";
|
|
3
3
|
import {log} from './log.js';
|
|
4
4
|
import {initializeTestService} from "./initializeTests";
|
|
5
|
+
import {dataContext} from "../src/services/contentProgress";
|
|
5
6
|
|
|
6
7
|
const {
|
|
7
8
|
fetchSongById,
|
|
@@ -158,6 +159,35 @@ describe('Sanity Queries', function () {
|
|
|
158
159
|
expect(response.entity[0].instrumentless).toBeDefined();
|
|
159
160
|
});
|
|
160
161
|
|
|
162
|
+
test('fetchAllSongsInProgress', async () => {
|
|
163
|
+
var mock = jest.spyOn(dataContext, 'fetchData');
|
|
164
|
+
var json = JSON.parse(`{"version":1,"config":{"key":1,"enabled":1,"checkInterval":1,"refreshInterval":2},"data":{"232979":{"s":"started","p":6,"t":20,"u":1731108082}}}`);
|
|
165
|
+
mock.mockImplementation(() =>
|
|
166
|
+
json);
|
|
167
|
+
const response = await fetchAll('drumeo', 'song',{progress:"in progress"});
|
|
168
|
+
expect(response.entity[0].id).toBe(232979);
|
|
169
|
+
expect(response.entity.length).toBe(1);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// test('fetchAllSongsCompleted', async () => {
|
|
173
|
+
// var mock = jest.spyOn(dataContext, 'fetchData');
|
|
174
|
+
// var json = JSON.parse(`{"version":1,"config":{"key":1,"enabled":1,"checkInterval":1,"refreshInterval":2},"data":{"232979":{"s":"completed","p":100,"t":20,"u":1731108082}}}`);
|
|
175
|
+
// mock.mockImplementation(() =>
|
|
176
|
+
// json);
|
|
177
|
+
// const response = await fetchAll('drumeo', 'song', {progress:"completed"});
|
|
178
|
+
// expect(response.entity[0].id).toBe(232979);
|
|
179
|
+
// expect(response.entity.length).toBe(1);
|
|
180
|
+
// });
|
|
181
|
+
//
|
|
182
|
+
// test('fetchAllSongsNotStarted', async () => {
|
|
183
|
+
// var mock = jest.spyOn(dataContext, 'fetchData');
|
|
184
|
+
// var json = JSON.parse(`{"version":1,"config":{"key":1,"enabled":1,"checkInterval":1,"refreshInterval":2},"data":{"198122":{"s":"started","p":100,"t":20,"u":1731108082},"231622":{"s":"completed","p":100,"t":20,"u":1731108082}}}`);
|
|
185
|
+
// mock.mockImplementation(() =>
|
|
186
|
+
// json); const response = await fetchAll('drumeo', 'song', {progress:"not started"});
|
|
187
|
+
// expect(response.entity[0].id).not.toBe(198122);
|
|
188
|
+
// expect(response.entity[0].id).not.toBe(231622);
|
|
189
|
+
// });
|
|
190
|
+
|
|
161
191
|
test('fetchSongFilterOptions', async () => {
|
|
162
192
|
const response = await fetchSongFilterOptions('drumeo', {});
|
|
163
193
|
log(response);
|