Methods
(static) calculateLongestStreaks() → {Object}
- Description:
- Calculates the longest daily, weekly streaks and totalPracticeSeconds from user practice dates.
- Source:
Returns:
-
Type
-
Object
(static) createPracticeNotes(payload) → {Promise.<Object>}
- Description:
- Creates practice notes for a specific date.
- Source:
Example
createPracticeNotes({ date: '2025-04-10', notes: 'Worked on scales and arpeggios' })
.then(response => console.log(response))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
payload |
Object
|
The data required to create practice notes.
Properties
| Name |
Type |
Description |
date |
string
|
The date for which to create notes (format: YYYY-MM-DD). |
notes |
string
|
The notes content to be saved. |
|
Returns:
- A promise that resolves to the API response after creating the notes.
-
Type
-
Promise.<Object>
(async, static) deletePracticeSession(day) → {Promise.<Array.<string>>}
- Description:
- Deletes all practice sessions for a specific day.
This function retrieves all user practice session IDs for a given day and sends a DELETE request
to remove them from the server. It also updates the local context to reflect the deletion.
- Source:
Parameters:
| Name |
Type |
Description |
day |
string
|
The day (in `YYYY-MM-DD` format) for which practice sessions should be deleted. |
Returns:
- A promise that resolves once the practice session is removed.
* @example
// Delete practice sessions for April 10, 2025
deletePracticeSession("2025-04-10")
.then(deletedIds => console.log("Deleted sessions:", response))
.catch(error => console.error("Delete failed:", error));
-
Type
-
Promise.<Array.<string>>
(static) deleteUserActivity(id) → {Promise.<Object>}
- Description:
- Deletes a specific user activity by its ID.
- Source:
Example
deleteUserActivity(789)
.then(response => console.log('Deleted:', response))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
id |
number
|
string
|
The ID of the user activity to delete. |
Returns:
- A promise that resolves to the API response after deletion.
-
Type
-
Promise.<Object>
(async, static) getPracticeNotes(day) → {Promise.<{data: Array.<Object>}>}
- Description:
- Retrieves user practice notes for a specific day.
- Source:
Example
// Get notes for April 10, 2025
getPracticeNotes("2025-04-10")
.then(({ data }) => console.log("Practice notes:", data))
.catch(error => console.error("Failed to get notes:", error));
Parameters:
| Name |
Type |
Description |
day |
string
|
The day (in `YYYY-MM-DD` format) to fetch practice notes for. |
Returns:
- A promise that resolves to an object containing the practice notes.
-
Type
-
Promise.<{data: Array.<Object>}>
(static) getPracticeSessions(params) → {Promise.<Object>}
- Description:
- Retrieves and formats a user's practice sessions for a specific day.
- Source:
Examples
// Get practice sessions for the current user on a specific day
getPracticeSessions({ day: "2025-03-31" })
.then(response => console.log(response))
.catch(error => console.error(error));
// Get practice sessions for another user
getPracticeSessions({ day: "2025-03-31", userId: 456 })
.then(response => console.log(response))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
params |
Object
|
Parameters for fetching practice sessions.
Properties
| Name |
Type |
Attributes |
Default |
Description |
day |
string
|
|
|
The date for which practice sessions should be retrieved (format: YYYY-MM-DD). |
userId |
number
|
<optional>
|
globalConfig.sessionConfig.userId
|
Optional user ID to retrieve sessions for a specific user. Defaults to the logged-in user. |
|
Returns:
- A promise that resolves to an object containing:
- `practices`: An array of formatted practice session data.
- `practiceDuration`: Total practice duration (in seconds) for the given day.
-
Type
-
Promise.<Object>
(async, static) getRecentActivity() → {Promise.<{data: Array.<Object>}>}
- Description:
- Retrieves the user's recent activity.
Returns an object containing recent practice activity.
- Source:
Example
// Fetch recent practice activity
getRecentActivity()
.then(({ data }) => console.log("Recent activity:", data))
.catch(error => console.error("Failed to get recent activity:", error));
Returns:
- A promise that resolves to an object containing recent activity items.
-
Type
-
Promise.<{data: Array.<Object>}>
(static) getUserMonthlyStats(paramsopt) → {Promise.<Object>}
- Description:
- Retrieves user activity statistics for a specified month and user, including daily and weekly activity data.
If no parameters are provided, defaults to the current year, current month, and the logged-in user.
- Source:
Examples
// Get stats for current user and month
getUserMonthlyStats().then(console.log);
// Get stats for March 2024
getUserMonthlyStats({ year: 2024, month: 2 }).then(console.log);
// Get stats for another user
getUserMonthlyStats({ userId: 123 }).then(console.log);
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
params |
Object
|
<optional>
|
{}
|
Parameters for fetching user statistics.
Properties
| Name |
Type |
Attributes |
Default |
Description |
year |
number
|
<optional>
|
new Date().getFullYear()
|
The year for which to retrieve the statistics. |
month |
number
|
<optional>
|
new Date().getMonth()
|
The 0-based month index (0 = January). |
day |
number
|
<optional>
|
1
|
The starting day (not used for grid calc, but kept for flexibility). |
userId |
number
|
<optional>
|
globalConfig.sessionConfig.userId
|
The user ID for whom to retrieve stats. |
|
Returns:
A promise that resolves to an object containing:
- `dailyActiveStats`: Array of daily activity data for the calendar grid.
- `weeklyActiveStats`: Array of weekly streak summaries.
- `practiceDuration`: Total number of seconds practiced in the month.
- `currentDailyStreak`: Count of consecutive active days.
- `currentWeeklyStreak`: Count of consecutive active weeks.
- `daysPracticed`: Total number of active days in the month.
-
Type
-
Promise.<Object>
(static) getUserWeeklyStats() → {Promise.<Object>}
- Description:
- Retrieves user activity statistics for the current week, including daily activity and streak messages.
- Source:
Example
// Retrieve user activity statistics for the current week
getUserWeeklyStats()
.then(stats => console.log(stats))
.catch(error => console.error(error));
Returns:
- A promise that resolves to an object containing weekly user activity statistics.
-
Type
-
Promise.<Object>
(static) recordUserActivity(payload) → {Promise.<Object>}
- Description:
- Records a new user activity in the system.
- Source:
Example
recordUserActivity({
user_id: 123,
action: 'start',
brand: 'pianote',
type: 'lesson',
content_id: 4561,
date: '2025-05-15'
}).then(response => console.log(response))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
payload |
Object
|
The data representing the user activity.
Properties
| Name |
Type |
Description |
user_id |
number
|
The ID of the user. |
action |
string
|
The type of action (e.g., 'start', 'complete', 'comment', etc.). |
brand |
string
|
The brand associated with the activity. |
type |
string
|
The content type (e.g., 'lesson', 'song', etc.). |
content_id |
number
|
The ID of the related content. |
date |
string
|
The date of the activity (ISO format). |
|
Returns:
- A promise that resolves to the API response after recording the activity.
-
Type
-
Promise.<Object>
(static) recordUserPractice(practiceDetails) → {Promise.<Object>}
- Description:
- Records a manual user practice data, updating the local database and syncing with remote.
- Source:
Example
// Record a manual practice session with a title
recordUserPractice({ title: "Some title", duration_seconds: 300 })
.then(response => console.log(response))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
practiceDetails |
Object
|
The details of the practice session.
Properties
| Name |
Type |
Attributes |
Description |
duration_seconds |
number
|
|
The duration of the practice session in seconds. |
title |
string
|
<optional>
|
The title of the practice session (max 64 characters). |
category_id |
number
|
<optional>
|
The ID of the associated category (if available). |
thumbnail_url |
string
|
<optional>
|
The URL of the session's thumbnail (max 255 characters). |
instrument_id |
number
|
<optional>
|
The ID of the associated instrument (if available). |
|
Returns:
- A promise that resolves to the response from logging the user practice.
-
Type
-
Promise.<Object>
(static) removeUserPractice(id) → {Promise.<void>}
- Description:
- Removes a user's practice session by ID, updating both the local and remote activity context.
- Source:
Example
// Remove a practice session with ID 123
removeUserPractice(123)
.then(() => console.log("Practice session removed successfully"))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
id |
number
|
The unique identifier of the practice session to be removed. |
Returns:
- A promise that resolves once the practice session is removed.
-
Type
-
Promise.<void>
(async, static) restorePracticeSession(date) → {Promise.<Object>}
- Description:
- Restores deleted practice sessions for a specific date.
Sends a PUT request to restore any previously deleted practices for a given date.
If restored practices are returned, they are added back into the local context.
- Source:
Example
// Restore practice sessions deleted on April 10, 2025
restorePracticeSession("2025-04-10")
.then(response => console.log("Practice session restored:", response))
.catch(error => console.error("Restore failed:", error));
Parameters:
| Name |
Type |
Description |
date |
string
|
The date (in `YYYY-MM-DD` format) for which deleted practice sessions should be restored. |
Returns:
- The response object from the API, containing practices for selected date.
-
Type
-
Promise.<Object>
(static) restoreUserActivity(id) → {Promise.<Object>}
- Description:
- Restores a specific user activity by its ID.
- Source:
Example
restoreUserActivity(789)
.then(response => console.log('Restored:', response))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
id |
number
|
string
|
The ID of the user activity to restore. |
Returns:
- A promise that resolves to the API response after restoration.
-
Type
-
Promise.<Object>
(static) restoreUserPractice(id) → {Promise.<Object>}
- Description:
- Restores a previously deleted user's practice session by ID
- Source:
Example
// Restore a deleted practice session with ID 123
restoreUserPractice(123)
.then(response => console.log("Practice session restored:", response))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
id |
number
|
The unique identifier of the practice session to be restored. |
Returns:
- A promise that resolves to the response containing the restored practice session data.
-
Type
-
Promise.<Object>
(static) updatePracticeNotes(payload) → {Promise.<Object>}
- Description:
- Updates existing practice notes for a specific date.
- Source:
Example
updatePracticeNotes({ date: '2025-04-10', notes: 'Updated: Focused on technique and timing' })
.then(response => console.log(response))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
payload |
Object
|
The data required to update practice notes.
Properties
| Name |
Type |
Description |
date |
string
|
The date for which to update notes (format: YYYY-MM-DD). |
notes |
string
|
The updated notes content. |
|
Returns:
- A promise that resolves to the API response after updating the notes.
-
Type
-
Promise.<Object>
(static) updateUserPractice(id, practiceDetails) → {Promise.<Object>}
- Description:
- Updates a user's practice session with new details and syncs the changes remotely.
- Source:
Example
// Update a practice session's duration
updateUserPractice(123, { duration_seconds: 600 })
.then(response => console.log(response))
.catch(error => console.error(error));
Parameters:
| Name |
Type |
Description |
id |
string
|
The unique identifier of the practice session to update. |
practiceDetails |
Object
|
The updated details of the practice session.
Properties
| Name |
Type |
Attributes |
Description |
duration_seconds |
number
|
<optional>
|
The duration of the practice session in seconds. |
category_id |
number
|
<optional>
|
The ID of the associated category (if available). |
title |
string
|
<optional>
|
The title of the practice session (max 64 characters). |
thumbnail_url |
string
|
<optional>
|
The URL of the session's thumbnail (max 255 characters). |
instrument_id |
number
|
<optional>
|
The ID of the associated instrument (if available). |
|
Returns:
- A promise that resolves to the response from updating the user practice.
-
Type
-
Promise.<Object>