Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The fetchRelatedLessons function provide related lessons for a specific content item,constructing a dynamic query that accounts for multiple relationship scenarios and sorting rules. Here’s a breakdown of how the related lessons are fetched and organized:
Child Lessons: Lessons that are direct children of the specified content (railContentId). These lessons are fetched with metadata like title, difficulty level, artist, and permission IDs.
Lessons by Artist (Same Type): Songs of the same type and brand where the artist matches that of the specified content. The lessons exclude the current railContentId and are ordered by published_on (descending) and title (ascending). The result is limited to 10 lessons.
Lessons by Genre (Same Type): Songs of the same type and brand where the genre matches that of the specified content. These lessons are also ordered by published_on (descending) and title (ascending), excluding the current railContentId and limited to 10 results.
Same Type with Custom Sort (by episode number): Lessons of the same type, where the type is listed in a predefined set (typeWithSortOrder). These lessons are sorted by the custom sort field (ascending), followed by title (ascending), limited to 10 results.
Same Type with Default Sort (by published-on): Lessons of the same type, but not in the typeWithSortOrder list. These are sorted by published_on (descending) and title (ascending). The result is limited to 10 lessons.
Each related lesson type is fetched uniquely and combined using array::unique to prevent duplicates. The total number of related lessons is limited to 10.