import { WorkerApiQualification } from 'worker-mturk-api' ; import { WorkerQualification } from 'types' ; export const calculateIfQualified = ( qualificationsArray ) => qualificationsArray . every ( qual => ! ! qual . caller_meets_requirement ) ; export const transformProjectRequirements = ( quals ) : WorkerQualification [ ] => quals . map ( ( qual ) : WorkerQualification => ( { qualificationId : qual . qualification_type_id , name : qual . qualification_type . name , description : qual . qualification_type . description , comparator : qual . comparator , hasTest : qual . qualification_type . has_test , requestable : qual . qualification_type . is_requestable , userValue : resolveUserQualificationValue ( qual ) , userMeetsQualification : ! ! qual . caller_meets_requirement , qualificationValues : qual . qualification_values } ) ) ; param qual const resolveUserQualificationValue = ( qual ) : string | number => { const { integer_value , locale_value : { country , subdivision } } = qual . caller_qualification_value ; if ( integer_value !== null && Number . isFinite ( integer_value ) ) { return integer_value ; } else if ( ! ! country && ! ! subdivision ) { return `${ country } - ${ subdivision }` ; } else if ( ! ! country ) { return country ; } else { return 'Not assigned.' ; } } ;