@@ -14,21 +14,37 @@ export class HistoryUseCases {
14
14
return allHistories ;
15
15
}
16
16
17
+ /**
18
+ * Creates a new User History Entry.
19
+ * (Note that just roomId isn't enough because the collaborator will also have a very similar History Entry)
20
+ * @returns Promise resolving when the history has been successfully created.
21
+ */
22
+ async createUserHistory ( questionId : string , roomId : string , attemptStartedAt : string , attemptCompletedAt : string , collaboratorId : string , attemptCode : string ) : Promise < void > {
23
+ if ( ! questionId || questionId . trim ( ) === ""
24
+ || ! roomId || roomId . trim ( ) === ""
25
+ || ! attemptStartedAt || attemptStartedAt . trim ( ) === ""
26
+ || ! attemptCompletedAt || attemptCompletedAt . trim ( ) === ""
27
+ || ! collaboratorId || collaboratorId . trim ( ) === "" ) {
28
+ throw new Error ( "Missing Attempt Details" ) ;
29
+ }
30
+ await this . historyRepository . createOrUpdateUserHistory ( questionId , roomId , attemptStartedAt , attemptCompletedAt , collaboratorId , attemptCode , true ) ;
31
+ }
32
+
17
33
/**
18
34
* Creates a new User History Entry. If there already exists a History Entry with the same userId (obtained in
19
35
* backend via JWT token and not passed here) and roomId, update the existing one instead.
20
36
* (Note that just roomId isn't enough because the collaborator will also have a very similar History Entry)
21
37
* @returns Promise resolving when the history has been successfully created.
22
38
*/
23
- async createOrUpdateUserHistory ( questionId : string , roomId : string , attemptStartedAt : string , attemptCompletedAt : string , collaboratorId : string , attemptCode : string ) : Promise < void > {
39
+ async updateUserHistory ( questionId : string , roomId : string , attemptStartedAt : string , attemptCompletedAt : string , collaboratorId : string , attemptCode : string ) : Promise < void > {
24
40
if ( ! questionId || questionId . trim ( ) === ""
25
41
|| ! roomId || roomId . trim ( ) === ""
26
42
|| ! attemptStartedAt || attemptStartedAt . trim ( ) === ""
27
43
|| ! attemptCompletedAt || attemptCompletedAt . trim ( ) === ""
28
44
|| ! collaboratorId || collaboratorId . trim ( ) === "" ) {
29
45
throw new Error ( "Missing Attempt Details" ) ;
30
46
}
31
- await this . historyRepository . createOrUpdateUserHistory ( questionId , roomId , attemptStartedAt , attemptCompletedAt , collaboratorId , attemptCode ) ;
47
+ await this . historyRepository . createOrUpdateUserHistory ( questionId , roomId , attemptStartedAt , attemptCompletedAt , collaboratorId , attemptCode , false ) ;
32
48
}
33
49
34
50
/**
0 commit comments