You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* This function queries the database for a user with the specified email. It allows for the inclusion of the user's password hash based on the includePassword parameter. If no user is found, it returns null. The function also handles errors by logging them and rethrowing the error for further handling.
125
+
*
126
+
* @param email - The email address of the user to retrieve.
127
+
* @param includePassword - A boolean indicating whether to include the user's password hash in the returned object.
128
+
* @returns An object containing user details, or null if no user is found.
129
+
* @throws Error If there is an issue querying the database.
* This function retrieves a user from the database based on the provided username. It executes a SQL query to fetch user details, including id, email, and role. If no user is found, it returns null. In case of an error during the query execution, it logs the error and rethrows it for further handling.
175
+
*
176
+
* @param {string} username - The username of the user to retrieve.
141
177
*/
142
178
exportasyncfunctiongetUserByUsername(username){
143
179
try{
@@ -171,7 +207,7 @@ export async function getUserByUsername(username) {
171
207
}
172
208
173
209
/**
174
-
* Update user last login timestamp
210
+
* Update the last login timestamp for a user.
175
211
*/
176
212
exportasyncfunctionupdateUserLastLogin(userId){
177
213
try{
@@ -187,7 +223,7 @@ export async function updateUserLastLogin(userId) {
187
223
}
188
224
189
225
/**
190
-
* Update user last seen timestamp
226
+
* Update user last seen timestamp in the database.
191
227
*/
192
228
exportasyncfunctionupdateUserLastSeen(userId){
193
229
try{
@@ -201,7 +237,13 @@ export async function updateUserLastSeen(userId) {
201
237
}
202
238
203
239
/**
204
-
* Update user password and encryption salt
240
+
* Update user password and encryption salt.
241
+
*
242
+
* This function updates the user's password hash and encryption salt in the database. It also clears all encrypted user data, as the previous data becomes unreadable with the new salt. Additionally, it invalidates all active user sessions to ensure security. The operation is performed within a transaction to maintain data integrity, and any errors during the process are logged for auditing purposes.
243
+
*
244
+
* @param {string} userId - The ID of the user whose password is being updated.
245
+
* @param {string} newPasswordHash - The new password hash to be set for the user.
246
+
* @param {string} newEncryptionSalt - The new encryption salt to be set for the user.
@@ -506,7 +613,11 @@ export async function getUserEncryptedData(userId, dataType) {
506
613
}
507
614
508
615
/**
509
-
* Get user statistics
616
+
* Get user statistics for a specific user.
617
+
*
618
+
* This function retrieves various statistics related to a user's progress, including the number of stages completed, total time spent, total sessions, average rating, and the timestamp of the last session. It executes a SQL query to gather this data from the user_progress table, filtering by the provided userId. If an error occurs during the query execution, it logs the error and rethrows it.
619
+
*
620
+
* @param {number} userId - The ID of the user for whom to retrieve statistics.
0 commit comments