musora-content-services 1.0.32 → 1.0.34
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 +2 -0
- package/babel.config.js +1 -0
- package/docs/config.js.html +2 -2
- package/docs/index.html +2 -2
- package/docs/module-Config.html +2 -2
- package/docs/module-Railcontent-Services.html +153 -108
- package/docs/module-Sanity-Services.html +27 -27
- package/docs/railcontent.js.html +40 -10
- package/docs/sanity.js.html +19 -12
- package/jest.config.js +7 -2
- package/package.json +5 -2
- package/src/contentTypeConfig.js +1 -1
- package/src/index.d.ts +4 -2
- package/src/index.js +4 -2
- package/src/services/railcontent.js +38 -7
- package/src/services/sanity.js +17 -10
- package/test/sanityQueryService.test.js +5 -4
|
@@ -7,9 +7,7 @@ const { globalConfig } = require('./config');
|
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the completion status of a specific song for the current user.
|
|
9
9
|
*
|
|
10
|
-
* @param {string} userId - The ID of the current user.
|
|
11
10
|
* @param {string} content_id - The ID of the song content to check.
|
|
12
|
-
* @param {string} token - The CSRF token for authentication.
|
|
13
11
|
* @returns {Promise<Object|null>} - Returns the completion status object if found, otherwise null.
|
|
14
12
|
* @example
|
|
15
13
|
* fetchCurrentSongComplete('user123', 'song456', 'csrf-token')
|
|
@@ -45,9 +43,7 @@ export async function fetchCurrentSongComplete(content_id) {
|
|
|
45
43
|
/**
|
|
46
44
|
* Fetches the completion status for multiple songs for the current user.
|
|
47
45
|
*
|
|
48
|
-
* @param {string} userId - The ID of the current user.
|
|
49
46
|
* @param {Array<string>} contentIds - An array of content IDs to check.
|
|
50
|
-
* @param {string} token - The CSRF token for authentication.
|
|
51
47
|
* @returns {Promise<Object|null>} - Returns an object containing completion statuses keyed by content ID, or null if an error occurs.
|
|
52
48
|
* @example
|
|
53
49
|
* fetchAllCompletedStates('user123', ['song456', 'song789'], 'csrf-token')
|
|
@@ -79,12 +75,10 @@ export async function fetchAllCompletedStates(contentIds) {
|
|
|
79
75
|
/**
|
|
80
76
|
* Fetches a list of songs that are currently in progress for the current user.
|
|
81
77
|
*
|
|
82
|
-
* @param {string} userId - The ID of the current user.
|
|
83
78
|
* @param {string} brand - The brand associated with the songs.
|
|
84
|
-
* @param {string} token - The CSRF token for authentication.
|
|
85
79
|
* @returns {Promise<Object|null>} - Returns an object containing in-progress songs if found, otherwise null.
|
|
86
80
|
* @example
|
|
87
|
-
* fetchSongsInProgress('
|
|
81
|
+
* fetchSongsInProgress('drumeo')
|
|
88
82
|
* .then(songs => console.log(songs))
|
|
89
83
|
* .catch(error => console.error(error));
|
|
90
84
|
*/
|
|
@@ -110,3 +104,40 @@ export async function fetchSongsInProgress(brand) {
|
|
|
110
104
|
return null;
|
|
111
105
|
}
|
|
112
106
|
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Fetches a list of content that is currently in progress for the current user.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} type - The content type associated with the content.
|
|
112
|
+
* @param {string} brand - The brand associated with the content.
|
|
113
|
+
* @returns {Promise<Object|null>} - Returns an object containing in-progress content if found, otherwise null.
|
|
114
|
+
* @example
|
|
115
|
+
* fetchContentInProgress('song', 'drumeo')
|
|
116
|
+
* .then(songs => console.log(songs))
|
|
117
|
+
* .catch(error => console.error(error));
|
|
118
|
+
*/
|
|
119
|
+
export async function fetchContentInProgress(type="all", brand) {
|
|
120
|
+
let url;
|
|
121
|
+
if(type!=="all") {
|
|
122
|
+
url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?brand=${brand}`;
|
|
123
|
+
} else {
|
|
124
|
+
url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?content_type=${type}&brand=${brand}`;
|
|
125
|
+
}
|
|
126
|
+
const headers = {
|
|
127
|
+
'Content-Type': 'application/json',
|
|
128
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
129
|
+
};
|
|
130
|
+
try {
|
|
131
|
+
const response = await fetch(url, { headers });
|
|
132
|
+
const result = await response.json();
|
|
133
|
+
if(result){
|
|
134
|
+
console.log('contentInProgress', result);
|
|
135
|
+
return result;
|
|
136
|
+
} else {
|
|
137
|
+
console.log('result not json');
|
|
138
|
+
}
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error('Fetch error:', error);
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
package/src/services/sanity.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Sanity-Services
|
|
3
3
|
*/
|
|
4
|
+
import {contentTypeConfig} from "../contentTypeConfig";
|
|
5
|
+
import {globalConfig} from "./config";
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
const { globalConfig } = require('./config');
|
|
7
|
-
|
|
8
|
-
import { fetchAllCompletedStates, fetchCurrentSongComplete } from './railcontent.js';
|
|
7
|
+
import { fetchAllCompletedStates, fetchCurrentSongComplete } from './railcontent.js';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Fetch a song by its document ID from Sanity.
|
|
@@ -20,6 +19,10 @@ import { fetchAllCompletedStates, fetchCurrentSongComplete } from './railcontent
|
|
|
20
19
|
*/
|
|
21
20
|
export async function fetchSongById(documentId) {
|
|
22
21
|
const fields = [
|
|
22
|
+
'"id": railcontent_id',
|
|
23
|
+
'railcontent_id',
|
|
24
|
+
'"type": _type',
|
|
25
|
+
'description',
|
|
23
26
|
'title',
|
|
24
27
|
'"thumbnail_url": thumbnail.asset->url',
|
|
25
28
|
'"style": genre[0]->name',
|
|
@@ -28,8 +31,9 @@ export async function fetchSongById(documentId) {
|
|
|
28
31
|
'instrumentless',
|
|
29
32
|
'soundslice',
|
|
30
33
|
'"resources": resource[]{resource_url, resource_name}',
|
|
34
|
+
'"url": web_url_path',
|
|
31
35
|
];
|
|
32
|
-
|
|
36
|
+
|
|
33
37
|
const query = `
|
|
34
38
|
*[_type == "song" && railcontent_id == ${documentId}]{
|
|
35
39
|
${fields.join(', ')}
|
|
@@ -144,11 +148,11 @@ export async function fetchRelatedSongs(brand, songId) {
|
|
|
144
148
|
}[0...10])
|
|
145
149
|
])[0...10]
|
|
146
150
|
}`;
|
|
147
|
-
|
|
151
|
+
|
|
148
152
|
// Fetch the related songs data
|
|
149
153
|
return fetchSanity(query, false);
|
|
150
154
|
}
|
|
151
|
-
|
|
155
|
+
|
|
152
156
|
/**
|
|
153
157
|
* Fetch all songs for a specific brand with pagination and search options.
|
|
154
158
|
* @param {string} brand - The brand for which to fetch songs.
|
|
@@ -289,7 +293,7 @@ export async function fetchNewReleases(brand) {
|
|
|
289
293
|
|
|
290
294
|
|
|
291
295
|
/**
|
|
292
|
-
* Fetch upcoming events for a specific brand that are within 48 hours before their `published_on` date
|
|
296
|
+
* Fetch upcoming events for a specific brand that are within 48 hours before their `published_on` date
|
|
293
297
|
* and are currently ongoing based on their `length_in_seconds`.
|
|
294
298
|
*
|
|
295
299
|
* This function retrieves events that have a `published_on` date within the last 48 hours or are currently
|
|
@@ -303,7 +307,7 @@ export async function fetchNewReleases(brand) {
|
|
|
303
307
|
* fetchLiveEvent('drumeo')
|
|
304
308
|
* .then(events => console.log(events))
|
|
305
309
|
* .catch(error => console.error(error));
|
|
306
|
-
*
|
|
310
|
+
*
|
|
307
311
|
*/
|
|
308
312
|
export async function fetchLiveEvent(brand) {
|
|
309
313
|
const baseLiveTypes = ["student-review", "student-reviews", "student-focus", "coach-stream", "live", "question-and-answer", "student-review", "boot-camps", "recording", "pack-bundle-lesson"];
|
|
@@ -511,7 +515,10 @@ export async function fetchAll(brand, type, {
|
|
|
511
515
|
break;
|
|
512
516
|
}
|
|
513
517
|
|
|
514
|
-
let defaultFields = [
|
|
518
|
+
let defaultFields = [
|
|
519
|
+
'"id": railcontent_id',
|
|
520
|
+
'railcontent_id',
|
|
521
|
+
'"type": _type',
|
|
515
522
|
'title',
|
|
516
523
|
'"image": thumbnail.asset->url',
|
|
517
524
|
'difficulty',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import {initializeService} from '../src/services/config.js';
|
|
2
|
+
|
|
1
3
|
const {
|
|
2
|
-
initializeService,
|
|
3
4
|
fetchSongById,
|
|
4
5
|
fetchArtists,
|
|
5
6
|
fetchSongArtistCount,
|
|
@@ -21,18 +22,18 @@ const {
|
|
|
21
22
|
fetchPackAll,
|
|
22
23
|
fetchPackChildren,
|
|
23
24
|
fetchLessonContent
|
|
24
|
-
} = require('../src/
|
|
25
|
+
} = require('../src/services/sanity.js');
|
|
25
26
|
|
|
26
27
|
describe('Sanity Queries', function () {
|
|
27
28
|
beforeEach(() => {
|
|
28
|
-
const config = {
|
|
29
|
+
const config = { 'sanityConfig':{
|
|
29
30
|
token: process.env.SANITY_API_TOKEN,
|
|
30
31
|
projectId: process.env.SANITY_PROJECT_ID,
|
|
31
32
|
dataset: process.env.SANITY_DATASET,
|
|
32
33
|
useCachedAPI: process.env.SANITY_USE_CACHED_API || true,
|
|
33
34
|
version: '2021-06-07',
|
|
34
35
|
debug: process.env.DEBUG || false
|
|
35
|
-
};
|
|
36
|
+
}};
|
|
36
37
|
initializeService(config);
|
|
37
38
|
});
|
|
38
39
|
|