@@ -178,22 +178,7 @@ export class KycService {
178178 const result = entity . getResult < KycNationalityData > ( ) ;
179179 const nationality = await this . countryService . getCountry ( result . nationality . id ) ;
180180
181- //Skip nationalities which needs a residencePermit first
182- if ( Config . kyc . residencePermitCountries . includes ( nationality . symbol ) ) continue ;
183-
184- const errors = this . getNationalityErrors ( entity , nationality ) ;
185- const comment = errors . join ( ';' ) ;
186-
187- if ( errors . some ( ( e ) => KycStepIgnoringErrors . includes ( e ) ) ) {
188- await this . kycStepRepo . update ( ...entity . ignored ( comment ) ) ;
189- } else if ( errors . length > 0 ) {
190- await this . kycStepRepo . update ( ...entity . manualReview ( comment ) ) ;
191- } else {
192- await this . kycStepRepo . update ( ...entity . complete ( ) ) ;
193- await this . checkDfxApproval ( entity ) ;
194- }
195-
196- await this . createStepLog ( entity . userData , entity ) ;
181+ await this . reviewNationalityData ( entity , entity . userData , nationality ) ;
197182 } catch ( e ) {
198183 this . logger . error ( `Failed to auto review nationality step ${ entity . id } :` , e ) ;
199184 }
@@ -586,21 +571,30 @@ export class KycService {
586571 data : Partial < UserData > ,
587572 reviewStatus : ReviewStatus ,
588573 ) : Promise < KycStepBase > {
589- let user = await this . getUser ( kycHash ) ;
574+ const user = await this . getUser ( kycHash ) ;
590575 const kycStep = user . getPendingStepOrThrow ( stepId ) ;
591576
592- if ( data . nationality ) {
593- const nationality = await this . countryService . getCountry ( data . nationality . id ) ;
594- if ( ! nationality ) throw new BadRequestException ( 'Nationality not found' ) ;
595-
596- Object . assign ( data . nationality , { id : nationality . id , symbol : nationality . symbol } ) ;
597- } else {
598- user = await this . userDataService . updateUserDataInternal ( user , data ) ;
599- }
577+ await this . userDataService . updateUserDataInternal ( user , data ) ;
600578
601579 return this . updateKycStepAndLog ( kycStep , user , data , reviewStatus ) ;
602580 }
603581
582+ async updateNationalityStep ( kycHash : string , stepId : number , data : KycNationalityData ) : Promise < KycStepBase > {
583+ const user = await this . getUser ( kycHash ) ;
584+ const kycStep = user . getPendingStepOrThrow ( stepId ) ;
585+
586+ const nationality = await this . countryService . getCountry ( data . nationality . id ) ;
587+ if ( ! nationality ) throw new BadRequestException ( 'Nationality not found' ) ;
588+
589+ Object . assign ( data . nationality , { id : nationality . id , symbol : nationality . symbol } ) ;
590+
591+ await this . reviewNationalityData ( kycStep , user , nationality , data ) ;
592+
593+ await this . updateProgress ( user , false ) ;
594+
595+ return KycStepMapper . toStepBase ( kycStep ) ;
596+ }
597+
604598 async updateBeneficialOwnerData ( kycHash : string , stepId : number , data : KycBeneficialData ) : Promise < KycStepBase > {
605599 const user = await this . getUser ( kycHash ) ;
606600 const kycStep = user . getPendingStepOrThrow ( stepId ) ;
@@ -1416,6 +1410,46 @@ export class KycService {
14161410 return errors ;
14171411 }
14181412
1413+ private async reviewNationalityData (
1414+ kycStep : KycStep ,
1415+ user : UserData ,
1416+ nationality : Country ,
1417+ data ?: KycStepResult ,
1418+ ) : Promise < void > {
1419+ if ( Config . kyc . residencePermitCountries . includes ( nationality . symbol ) ) {
1420+ if ( data ) {
1421+ await this . kycStepRepo . update ( ...kycStep . update ( ReviewStatus . INTERNAL_REVIEW , data ) ) ;
1422+ await this . createStepLog ( user , kycStep ) ;
1423+ }
1424+ return ;
1425+ }
1426+
1427+ const errors = this . getNationalityErrors ( kycStep , nationality ) ;
1428+ const comment = errors . join ( ';' ) ;
1429+
1430+ if ( data ) {
1431+ if ( errors . some ( ( e ) => KycStepIgnoringErrors . includes ( e ) ) ) {
1432+ await this . kycStepRepo . update ( ...kycStep . update ( ReviewStatus . IGNORED , data , comment ) ) ;
1433+ } else if ( errors . length > 0 ) {
1434+ await this . kycStepRepo . update ( ...kycStep . update ( ReviewStatus . MANUAL_REVIEW , data , comment ) ) ;
1435+ } else {
1436+ await this . kycStepRepo . update ( ...kycStep . update ( ReviewStatus . COMPLETED , data ) ) ;
1437+ await this . checkDfxApproval ( kycStep ) ;
1438+ }
1439+ } else {
1440+ if ( errors . some ( ( e ) => KycStepIgnoringErrors . includes ( e ) ) ) {
1441+ await this . kycStepRepo . update ( ...kycStep . ignored ( comment ) ) ;
1442+ } else if ( errors . length > 0 ) {
1443+ await this . kycStepRepo . update ( ...kycStep . manualReview ( comment ) ) ;
1444+ } else {
1445+ await this . kycStepRepo . update ( ...kycStep . complete ( ) ) ;
1446+ await this . checkDfxApproval ( kycStep ) ;
1447+ }
1448+ }
1449+
1450+ await this . createStepLog ( user , kycStep ) ;
1451+ }
1452+
14191453 private getFinancialDataErrors ( entity : KycStep ) : KycError [ ] {
14201454 const errors = this . getStepDefaultErrors ( entity ) ;
14211455 const financialStepResult = entity . getResult < KycFinancialResponse [ ] > ( ) ;
0 commit comments