import { HitDatabaseEntry , HitDatabaseMap , WorkerHitDatabaseEntry , HitId , LegacyDateFormat } from '../types' ; import { Map } from 'immutable' ; import { StatusDetailPageInfo } from '../api/statusDetail' ; import { StatusDetailApiResponse , WorkerSubmittedHit } from '../worker-mturk-api' ; import { STATUS_DETAIL_RESULTS_PER_PAGE } from '../constants/misc' ; export const parseStatusDetailPage = ( data , legacyDateString ) : StatusDetailPageInfo => { try { return { data : tabulateHitDbEntries ( data . results , legacyDateString ) , morePages : detectMorePages ( data ) } ; } catch ( e ) { console . warn ( e ) ; return { data : Map < HitId , HitDatabaseEntry > ( ) , morePages : false } ; } } ; const tabulateHitDbEntries = ( hits , legacyDateString ) : HitDatabaseMap => hits . reduce ( ( map , hit ) => { return map . set ( hit . hit_id , generateHitDbEntry ( hit , legacyDateString ) ) ; } , Map < HitId , WorkerHitDatabaseEntry > ( ) ) ; const generateHitDbEntry = ( submittedHit , dateString ) : WorkerHitDatabaseEntry => { const { hit_id , requester_id , requester_name , requester_feedback , reward : { amount_in_dollars } , title , state , assignment_id } = submittedHit ; return { id : hit_id , reward : amount_in_dollars , bonus : 0 , requester : { id : requester_id , name : requester_name } , date : dateString , status : state , title : title , assignmentId : assignment_id , feedback : requester_feedback || undefined } ; } ; const detectMorePages = ( data ) : boolean => STATUS_DETAIL_RESULTS_PER_PAGE * data . page_number < data . total_num_results ;