@@ -8,83 +8,59 @@ export class CalculationsRepository implements ICalculationsRepository {
8
8
remoteDataSource : IStorageRepository = IStorageRepository . instance ;
9
9
10
10
async storeCalculation ( calculationData : CalculationData ) : Promise < void > {
11
- try {
12
- const oldCalculations = await this . getAllCalculations ( ) ;
13
- const newCalculations = [ calculationData , ...oldCalculations ] ;
14
- await this . remoteDataSource . set ( {
15
- allCalculations : JSON . stringify ( newCalculations ) ,
16
- } ) ;
17
- } catch ( e : unknown ) {
18
- throw Error ( e as string ) ;
19
- }
11
+ const oldCalculations = await this . getAllCalculations ( ) ;
12
+ const newCalculations = [ calculationData , ...oldCalculations ] ;
13
+ await this . remoteDataSource . set ( {
14
+ allCalculations : JSON . stringify ( newCalculations ) ,
15
+ } ) ;
20
16
}
21
17
22
18
async cacheOngoingCalculation (
23
19
calculationData : CalculationData
24
20
) : Promise < void > {
25
- try {
26
- await this . remoteDataSource . set ( {
27
- ongoingCalculation : JSON . stringify ( calculationData ) ,
28
- } ) ;
29
- } catch ( e : unknown ) {
30
- throw Error ( e as string ) ;
31
- }
21
+ await this . remoteDataSource . set ( {
22
+ ongoingCalculation : JSON . stringify ( calculationData ) ,
23
+ } ) ;
32
24
}
33
25
34
26
async clearOngoingCalculation ( ) : Promise < void > {
35
- try {
36
- await this . remoteDataSource . set ( {
37
- ongoingCalculation : null ,
38
- } ) ;
39
- } catch ( e : unknown ) {
40
- throw Error ( e as string ) ;
41
- }
27
+ await this . remoteDataSource . set ( {
28
+ ongoingCalculation : null ,
29
+ } ) ;
42
30
}
43
31
44
32
async getAllCalculations ( ) : Promise < CalculationData [ ] > {
45
- try {
46
- const data = await this . remoteDataSource . get ( {
47
- allCalculations : JSON . stringify ( [ ] ) ,
48
- } ) ;
33
+ const data = await this . remoteDataSource . get ( {
34
+ allCalculations : JSON . stringify ( [ ] ) ,
35
+ } ) ;
49
36
50
- return JSON . parse (
51
- data [ "allCalculations" ] as string
52
- ) as CalculationData [ ] ;
53
- } catch ( e : unknown ) {
54
- throw Error ( e as string ) ;
55
- }
37
+ return JSON . parse (
38
+ data [ "allCalculations" ] as string
39
+ ) as CalculationData [ ] ;
56
40
}
57
41
58
42
async _getOngoingCalculation ( ) : Promise < CalculationData | null > {
59
- try {
60
- const data = await this . remoteDataSource . get ( {
61
- ongoingCalculation : null ,
62
- } ) ;
43
+ const data = await this . remoteDataSource . get ( {
44
+ ongoingCalculation : null ,
45
+ } ) ;
63
46
64
- if ( data [ "ongoingCalculation" ] !== null ) {
65
- return JSON . parse (
66
- data [ "ongoingCalculation" ] as string
67
- ) as CalculationData ;
68
- }
69
- return null ;
70
- } catch ( e : unknown ) {
71
- throw Error ( e as string ) ;
47
+ if ( data [ "ongoingCalculation" ] !== null ) {
48
+ return JSON . parse (
49
+ data [ "ongoingCalculation" ] as string
50
+ ) as CalculationData ;
72
51
}
52
+ return null ;
73
53
}
74
54
75
55
async getLastCalculation ( ) : Promise < CalculationData | null > {
76
- try {
77
- const ongoingCalculation = await this . _getOngoingCalculation ( ) ;
78
- if ( ongoingCalculation !== null ) {
79
- return ongoingCalculation ;
80
- }
81
- const oldCalculations = await this . getAllCalculations ( ) ;
82
- if ( oldCalculations . length > 0 ) {
83
- return oldCalculations [ 0 ] ;
84
- }
85
- return null ;
86
- } catch ( e : unknown ) {
87
- throw Error ( e as string ) ;
56
+ const ongoingCalculation = await this . _getOngoingCalculation ( ) ;
57
+ if ( ongoingCalculation !== null ) {
58
+ return ongoingCalculation ;
59
+ }
60
+ const oldCalculations = await this . getAllCalculations ( ) ;
61
+ if ( oldCalculations . length > 0 ) {
62
+ return oldCalculations [ 0 ] ;
88
63
}
64
+ return null ;
89
65
}
90
66
}
0 commit comments