Playlists

Members

(inner, constant) excludeFromGeneratedIndex :Array.<string>

Description:
  • Exported functions that are excluded from index generation.
Source:
Exported functions that are excluded from index generation.
Type:
  • Array.<string>

Methods

(static) addItemToPlaylist(payload) → {Promise.<(Object|null)>}

Description:
  • Adds an item to one or more playlists
Source:
Example
const payload = {
    content_id: 123,
    playlist_id: [1, 2, 3],
    position: 2,

};

addItemToPlaylist(payload)
  .then(response => {
    if (response?.success) {
      console.log("Item(s) added to playlist successfully");
    }
    if (response?.limit_exceeded) {
      console.warn("Some playlists exceeded the item limit:", response.limit_exceeded);
    }
  })
  .catch(error => {
    console.error("Error adding item to playlist:", error);
  });
Parameters:
Name Type Description
payload AddItemToPlaylistDTO The request payload containing necessary parameters.
Throws:
- Throws an error if the request encounters issues during the operation.
Type
Error
Returns:
- A promise that resolves to an object with the response data, including: - `added` (Array): Playlist ids that we were success - `limit_exceeded` (Array): A list of playlists where the item limit was exceeded, if any. - `unauthorized` (Array): A list of successfully added items (empty if none). Resolves to `null` if the request fails.
Type
Promise.<(Object|null)>

(static) createPlaylist(playlistData) → {Promise.<Playlist>}

Description:
  • Creates a new user playlist by sending a POST request with playlist data to the API. This function calls the `/playlists/playlist` endpoint, where the server validates the incoming data and associates the new playlist with the authenticated user. The `name` field is required, while other fields are optional.
Source:
Example
createPlaylist({ name: "My Playlist", description: "A cool playlist", private: true })
  .then(response => console.log(response))
  .catch(error => console.error('Error creating playlist:', error));
Parameters:
Name Type Description
playlistData CreatePlaylistDTO An object containing data to create the playlist. The fields include: - `name` (string): The name of the new playlist (required, max 255 characters). - `description` (string): A description of the playlist (optional, max 1000 characters). - `category` (string): The category of the playlist. - `private` (boolean): Whether the playlist is private (optional, defaults to false). - `brand` (string): Brand identifier for the playlist.
Returns:
- A promise that resolves to the created playlist data if successful, or an error response if validation fails.
Type
Promise.<Playlist>

(static) deletePlaylist(playlist) → {Promise.<(any|string|null)>}

Description:
  • Soft deletes a playlist. Will cascade and also soft delete entries in other playlist tables (pinned, reported, liked, playlist content) and last engaged that have this playlist id
Source:
Parameters:
Name Type Description
playlist id the id of the playlist you want to soft delete.
Returns:
Type
Promise.<(any|string|null)>

(static) duplicatePlaylist(playlistId, playlistData) → {Promise.<Playlist>}

Description:
  • Duplicates a playlist and playlist items for the provided playlistID for the authorized user
Source:
Example
duplicatePlaylist(81167, { name: "My Playlist (Duplicate)", description: "A cool playlist", private: true })
  .then(response => console.log(response))
  .catch(error => console.error('Error creating playlist:', error));
Parameters:
Name Type Description
playlistId string | number
playlistData DuplicatePlaylistDTO An object containing data to create the playlist. The fields include: - `name` (string): The name of the new playlist (required, max 255 characters). - `description` (string): A description of the playlist (optional, max 1000 characters). - `category` (string): The category of the playlist. - `private` (boolean): Whether the playlist is private (optional, defaults to false). - `brand` (string): Brand identifier for the playlist. - 'items' (array): List of playlist items to duplicate in updated order
Returns:
Type
Promise.<Playlist>

(static) fetchPlaylist(playlistId) → {Promise.<Object>}

Description:
  • Retrieves details of a specific playlist by its ID. This function sends a GET request to the `/playlists/playlist` endpoint with a specified playlist ID. The server validates the user's access to the playlist and returns playlist details if the user is authorized.
Source:
Example
fetchPlaylist(12345)
  .then(response => console.log(response.data))
  .catch(error => console.error('Error fetching playlist:', error));
Parameters:
Name Type Description
playlistId string | number The unique identifier of the playlist to retrieve.
Returns:
- A promise that resolves to the response from the API, containing: - `data` (Object): The playlist details, or an error message if access is denied or the playlist is not found.
Type
Promise.<Object>

(static) fetchPlaylistItems(playlistId) → {Promise.<Array.<Object>>}

Description:
  • Retrieves items within a specified playlist by playlist ID. This function sends a GET request to the `/playlists/playlist-lessons` endpoint to fetch items in the given playlist. The server combines data from the playlist and additional metadata from Sanity to enhance item details.
Source:
Example
fetchPlaylistItems(12345)
  .then(items => console.log(items))
  .catch(error => console.error('Error fetching playlist items:', error));
Parameters:
Name Type Description
playlistId string | number The unique identifier of the playlist whose items are to be fetched.
Returns:
- A promise that resolves to an array of playlist items
Type
Promise.<Array.<Object>>

(static) fetchUserPlaylists(brand) → {Promise.<(Object|null)>}

Description:
  • Fetches user playlists for a specific brand. Allows optional pagination, sorting, and search parameters to control the result set.
Source:
Example
fetchUserPlaylists('drumeo', { page: 1, sort: 'name', searchTerm: 'rock' })
  .then(playlists => console.log(playlists))
  .catch(error => console.error(error));
Parameters:
Name Type Attributes Default Description
brand string The brand identifier for which playlists are being fetched.
params.limit number <optional>
10 The maximum number of playlists to return per page (default is 10).
params.page number <optional>
1 The page number for pagination.
params.sort string <optional>
'-created_at' The sorting order for the playlists (default is by created_at in descending order).
params.content_id int | string <optional>
If content_id exists, the endpoint checks in each playlist if we have the content in the items.
Returns:
- A promise that resolves to the response from the API, containing the user playlists data.
Type
Promise.<(Object|null)>

(static) togglePlaylistPrivate(playlistId, is_private) → {Promise.<Playlist>}

Description:
  • Toggles a playlists public/private state
Source:
Example
togglePlaylistPrivate(11541, true)
  .then(response => console.log(response))
  .catch(error => console.error('Error creating playlist:', error));
Parameters:
Name Type Description
playlistId string | number
is_private Boolean flag for private/public
Returns:
- A promise that resolves to the updated playlist data if successful, or an error response if validation fails.
Type
Promise.<Playlist>

(static) undeletePlaylist(playlist) → {Promise.<(any|string|null)>}

Description:
  • Soft restores a playlist. Will cascade and also soft restore entries in other playlist tables (pinned, reported, liked, playlist content) and last engaged that have this playlist id
Source:
Parameters:
Name Type Description
playlist id the id of the playlist you want to soft restore.
Returns:
Type
Promise.<(any|string|null)>

(static) updatePlaylist(playlistId, updateData) → {Promise.<object>}

Description:
  • Updates a playlists values
Source:
Example
updatePlaylist(661113 { name: "My Playlist", description: "A cool playlist", is_private: true, deleted_items : [2189832, 221091] })
  .then(response => console.log(response.playlist); console.log(response.lessons))
  .catch(error => console.error('Error updating playlist:', error));
Parameters:
Name Type Description
playlistId string | number
updateData UpdatePlaylistDTO An object containing fields to update on the playlist: - `name` (string): The name of the new playlist (required, max 255 characters). - `description` (string): A description of the playlist (optional, max 1000 characters). - `category` (string): The category of the playlist (optional). - `is_private` (boolean): Whether the playlist is private (optional, defaults to false). - `deleted_items` (array): List of playlist item IDs to delete (optional). - `item_order` (array): Updated order of playlist items (ids, not railcontent_ids) (optional).
Returns:
- A promise that resolves to the created playlist data and lessons if successful, or an error response if validation fails. The server response includes: - `playlist`: Playlist metadata (same as fetchPlaylist) - `lessons`: Updated list of plalyist lessons (same as fetchPlaylistItems)
Type
Promise.<object>

(async, inner) deleteItemsFromPlaylist(playlistId, deleted_items) → {Promise.<Object>}

Description:
  • Delete Items from playlist
Source:
Example
// Delete items 8462221 and 8462222 from playlist 81111
try {
  const response = await deleteItemsFromPlaylist(81111, [8462221, 8462222]);
} catch (error) {
  console.error('Failed to delete playlist items:', error);
}
Parameters:
Name Type Description
playlistId string | number The unique identifier of the playlist to update.
deleted_items array list of playlist ids to delete (user_playlist_item_id, not the railcontent_id)
Returns:
Type
Promise.<Object>

(async, inner) likePlaylist(playlistId) → {Promise.<Object>}

Description:
  • Likes a playlist for the current user.
Source:
Example
// Like playlist with ID '123'
try {
  const response = await likePlaylist('123');
  console.log('Playlist liked successfully:', response);
} catch (error) {
  console.error('Failed to like playlist:', error);
}
Parameters:
Name Type Description
playlistId string | number The unique identifier of the playlist to like.
Returns:
Type
Promise.<Object>

(async, inner) reportPlaylist(playlistId) → {Promise.<Object>}

Description:
  • Reports a playlist
Source:
Example
// Report playlist with ID '123'
try {
  const response = await reportPlaylist('123');
  console.log('Playlist reported successfully:', response);
} catch (error) {
  console.error('Failed to report playlist:', error);
}
Parameters:
Name Type Description
playlistId string | number The unique identifier of the playlist to report.
Returns:
Type
Promise.<Object>

(async, inner) restoreItemFromPlaylist(playlistItemId) → {Promise.<Object>}

Description:
  • Restore items
Source:
Example
// Restore item 8462221
try {
  const response = await restoreItemFromPlaylist(8462221);
} catch (error) {
  console.error('Failed to restore playlist item:', error);
}
Parameters:
Name Type Description
playlistItemId string | number The unique identifier of the playlist ite to restore.
Returns:
Type
Promise.<Object>

(async, inner) unlikePlaylist(playlistId) → {Promise.<Object>}

Description:
  • Unlikes a previously liked playlist.
Source:
Example
// Unlike playlist with ID '123'
try {
  const response = await unlikePlaylist('123');
  console.log('Playlist unliked successfully:', response);
} catch (error) {
  console.error('Failed to unlike playlist:', error);
}
Parameters:
Name Type Description
playlistId string | number The unique identifier of the playlist to unlike.
Returns:
Type
Promise.<Object>