import { HitDatabaseEntry , HitStatus } from '../types' ; export const conflictsPreserveBonus = ( oldEntry , newEntry ) : HitDatabaseEntry => { return { ... newEntry , bonus : oldEntry . bonus } ; } ; enum Status { SUBMITTED = 'Submitted' , PENDING_PAYMENT = 'Pending Payment' , PENDING_APPROVAL = 'Pending Approval' , APROVED = 'Approved' , PAID = 'Paid' , REJECTED = 'Rejected' } const paidOrApprovedStatuses = new Set < HitStatus > ( [ Status . PAID , Status . PENDING_PAYMENT , Status . APROVED ] ) ; const pendingStatuses = new Set < HitStatus > ( [ Status . PENDING_APPROVAL , Status . PENDING_PAYMENT , Status . SUBMITTED , Status . APROVED ] ) ; const approvedButNotPaidStatuses = new Set < HitStatus > ( [ Status . PENDING_APPROVAL , Status . APROVED ] ) ; export const isPaidOrApproved = ( el ) => paidOrApprovedStatuses . has ( el . status ) ; export const isPending = ( el ) => pendingStatuses . has ( el . status ) ; export const isApprovedButNotPaid = ( el ) => approvedButNotPaidStatuses . has ( el . status ) ; export const isNotRejected = ( el ) => el . status !== Status . REJECTED ; export const isRejected = ( el ) => el . status === Status . REJECTED ; export const calculateAcceptanceRate = ( total , rejected ) => ( total - rejected ) / total * 100 ; export const calculateThreshold = ( total , minimumRate ) => Math . ceil ( ( minimumRate * total / 100 - total ) * - 1 ) ; export const rewardAndBonus = ( hit ) => hit . reward + ( hit . bonus || 0 ) ;