Skip to content

Commit

Permalink
comments and fix a hidden build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
macrael committed Apr 15, 2024
1 parent dc11a52 commit af49041
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ import {
} from './prismaSharedContractRateHelpers'
import type { ContractTableFullPayload } from './prismaSubmittedContractHelpers'

// This function might be generally useful later on. It takes an array of objects
// that can be errors and either returns the first error, or returns the list but with
// the assertion that none of the elements in the array are errors.
function arrayOrFirstError<T>(
arrayWithPossibleErrors: (T | Error)[]
): T[] | Error {
if (arrayWithPossibleErrors.every((i): i is T => !(i instanceof Error))) {
return arrayWithPossibleErrors
}

const firstError = arrayWithPossibleErrors.find(
(t): t is Error => t instanceof Error
)
if (!firstError) {
return Error(
'Should Not Happen: something in the array was an error but we couldnt find it'
)
}

return firstError
}

// parseContractWithHistory returns a ContractType with a full set of
// ContractRevisions in reverse chronological order. Each revision is a change to this
// Contract with submit and unlock info. Changes to the data of this contract, or changes
Expand Down Expand Up @@ -139,20 +161,17 @@ function contractWithHistoryToDomainModel(
}

// if we have a draft revision, we should set draftRates
const draftRatesOrError = contract.draftRates.map((dr) =>
const draftRatesOrErrors = contract.draftRates.map((dr) =>
rateWithHistoryToDomainModel(dr.rate)
)
const firstError: Error | undefined = draftRatesOrError.find(
(dr): dr is Error => dr instanceof Error
)
if (firstError) {
return firstError
} else {
const allDraftRates: RateType[] =
draftRatesOrError as RateType[]
draftRates = allDraftRates

const draftRatesOrError = arrayOrFirstError(draftRatesOrErrors)
if (draftRatesOrError instanceof Error) {
return draftRatesOrError
}

draftRates = draftRatesOrError

if (draftRates.length === 0) {
console.info(
'Checking for old style draft rates, this code should go when migrated to new draft-rates table.'
Expand Down
7 changes: 1 addition & 6 deletions services/app-api/src/testHelpers/emailerHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,7 @@ const mockContractRev = (
rateRevisions: [
{
id: '12345',
rate: {
id: 'rate-id',
stateCode: 'MN',
stateNumber: 3,
createdAt: new Date(11 / 27 / 2023),
},
rateID: '6789',
submitInfo: undefined,
unlockInfo: undefined,
createdAt: new Date(11 / 27 / 2023),
Expand Down

0 comments on commit af49041

Please sign in to comment.