@@ -58,7 +58,8 @@ class LemonRepository {
5858 return { ok : false , error : new Error ( 'Wrong password' ) } ;
5959 }
6060 const ok = this . db . setBank ( profile . account_id , bank ) ;
61- return { ok, error : null } ;
61+ if ( ! ok ) return { ok, error : new Error ( 'Database error' ) } ;
62+ return setCards ( bank ) ;
6263 }
6364
6465 /** @return Array<Card>, error */
@@ -74,22 +75,8 @@ class LemonRepository {
7475 }
7576
7677 /** @return boolean, error */
77- async setCard ( user ) {
78+ async setCards ( bank ) {
7879 try {
79- const profile = this . db . getAccount ( user . login ) ;
80- if ( ! profile ) {
81- return { ok : false , error : new Error ( 'Account Not Found' ) } ;
82- }
83- if ( ! profile . token ) {
84- return { ok : false , error : new Error ( 'Account Has No Token' ) } ;
85- }
86- if ( user . password !== profile . password ) {
87- return { ok : false , error : new Error ( 'Wrong password' ) } ;
88- }
89- const bank = this . db . getMonobank ( profile ) ;
90- if ( ! bank ) {
91- return { ok : false , error : new Error ( 'No cards present' ) } ;
92- }
9380 const monoCards = await this . monoDS . getAccounts ( bank . token ) ;
9481 const monoAccounts = monoCards . accounts ;
9582 const ok = this . db . setMonoCards ( monoAccounts , profile ) ;
@@ -114,17 +101,14 @@ class LemonRepository {
114101 try {
115102 const profile = this . db . getAccount ( user . login ) ;
116103 if ( ! profile ) {
117- throw new Error ( 'Account Not Found' ) ;
118- }
119- if ( ! profile . token ) {
120- return { transactions : null , error : new Error ( 'Account Has No Token' ) } ;
104+ return { transactions : null , error : new Error ( 'Account Not Found' ) } ;
121105 }
122106 if ( user . password !== profile . password ) {
123- throw new Error ( 'Wrong password' ) ;
107+ return { transactions : null , error : new Error ( 'Wrong password' ) } ;
124108 }
125109 const bank = this . db . getMonobank ( profile ) ;
126110 if ( ! bank ) {
127- throw new Error ( 'No cards present' ) ;
111+ return { transactions : null , error : new Error ( 'No cards present' ) } ;
128112 }
129113 const cards = this . db . getCards ( profile . account_id ) ;
130114 const accounts = this . _formMonoTrRequest ( cards ) ;
0 commit comments