@@ -442,38 +442,49 @@ export const checkSanctionedGeoArea = async (
442442 candidate : Candidate ,
443443) : Promise < boolean > => {
444444 try {
445- const location = await queries . getCandidateLocation (
446- candidate . slotId ,
447- candidate . name ,
448- ) ;
449- if ( location && location . region && location . country ) {
450- const sanctionedCountries = config . constraints ?. sanctionedCountries . map (
451- ( x ) => x . trim ( ) . toLowerCase ( ) ,
452- ) ;
453- const sanctionedRegions = config . constraints ?. sanctionedRegions . map ( ( x ) =>
454- x . trim ( ) . toLowerCase ( ) ,
455- ) ;
445+ if (
446+ ! config . constraints ?. sanctionedGeoArea ?. sanctionedCountries ?. length &&
447+ ! config . constraints ?. sanctionedGeoArea ?. sanctionedRegions ?. length
448+ ) {
449+ setSanctionedGeoAreaValidity ( candidate , true ) ;
450+ return true ;
451+ }
456452
457- if (
458- sanctionedCountries . includes ( location . country . trim ( ) . toLowerCase ( ) ) ||
459- sanctionedRegions . includes ( location . region . trim ( ) . toLowerCase ( ) )
460- ) {
461- logger . info (
462- `${ candidate . name } is in a sanctioned location: Country: ${ location . country } , Region: ${ location . region } ` ,
463- {
464- label : "Constraints" ,
465- } ,
466- ) ;
467- await setSanctionedGeoAreaValidity ( candidate . slotId , false ) ;
468- return false ;
469- } else {
470- await setSanctionedGeoAreaValidity ( candidate . slotId , true ) ;
471- return true ;
472- }
473- } else {
474- await setSanctionedGeoAreaValidity ( candidate . slotId , true ) ;
453+ const location = await queries . getCandidateLocation ( candidate . slotId ) ;
454+ if ( ! location ?. region || ! location ?. country ) {
455+ setSanctionedGeoAreaValidity ( candidate , true ) ;
475456 return true ;
476457 }
458+
459+ const sanctionedCountries = config . constraints ?. sanctionedGeoArea
460+ ?. sanctionedCountries
461+ ? config . constraints . sanctionedGeoArea . sanctionedCountries . map ( ( x ) =>
462+ x . trim ( ) . toLowerCase ( ) ,
463+ )
464+ : [ ] ;
465+ const sanctionedRegions = config . constraints ?. sanctionedGeoArea
466+ ?. sanctionedRegions
467+ ? config . constraints . sanctionedGeoArea . sanctionedRegions . map ( ( x ) =>
468+ x . trim ( ) . toLowerCase ( ) ,
469+ )
470+ : [ ] ;
471+
472+ if (
473+ sanctionedCountries . includes ( location . country . trim ( ) . toLowerCase ( ) ) ||
474+ sanctionedRegions . includes ( location . region . trim ( ) . toLowerCase ( ) )
475+ ) {
476+ logger . info (
477+ `${ candidate . name } is in a sanctioned location: Country: ${ location . country } , Region: ${ location . region } ` ,
478+ {
479+ label : "Constraints" ,
480+ } ,
481+ ) ;
482+ await setSanctionedGeoAreaValidity ( candidate , false ) ;
483+ return false ;
484+ }
485+
486+ await setSanctionedGeoAreaValidity ( candidate , true ) ;
487+ return true ;
477488 } catch ( e ) {
478489 logger . error (
479490 `Error checking location for sanctions: ${ e } ` ,
0 commit comments