Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
macrael committed Oct 2, 2023
1 parent c4e7c3e commit b6c4b35
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 47 deletions.
21 changes: 18 additions & 3 deletions services/app-api/src/postgres/contractAndRates/insertContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,28 @@ async function insertDraftContract(
contractType: contractType,
contractExecutionStatus,
contractDocuments: {
create: contractDocuments,
create:
contractDocuments &&
contractDocuments.map((d, idx) => ({
position: idx,
...d,
})),
},
supportingDocuments: {
create: supportingDocuments,
create:
supportingDocuments &&
supportingDocuments.map((d, idx) => ({
position: idx,
...d,
})),
},
stateContacts: {
create: stateContacts,
create:
stateContacts &&
stateContacts.map((c, idx) => ({
position: idx,
...c,
})),
},
contractDateStart,
contractDateEnd,
Expand Down
28 changes: 24 additions & 4 deletions services/app-api/src/postgres/contractAndRates/insertRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,20 @@ async function insertDraftRate(
rateType,
rateCapitationType: rateCapitationType,
rateDocuments: {
create: rateDocuments,
create:
rateDocuments &&
rateDocuments.map((d, idx) => ({
position: idx,
...d,
})),
},
supportingDocuments: {
create: supportingDocuments,
create:
supportingDocuments &&
supportingDocuments.map((d, idx) => ({
position: idx,
...d,
})),
},
rateDateStart,
rateDateEnd,
Expand All @@ -67,10 +77,20 @@ async function insertDraftRate(
rateProgramIDs,
rateCertificationName,
certifyingActuaryContacts: {
create: certifyingActuaryContacts,
create:
certifyingActuaryContacts &&
certifyingActuaryContacts.map((c, idx) => ({
position: idx,
...c,
})),
},
addtlActuaryContacts: {
create: addtlActuaryContacts,
create:
addtlActuaryContacts &&
addtlActuaryContacts.map((c, idx) => ({
position: idx,
...c,
})),
},
actuaryCommunicationPreference,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,7 @@ import { includeDraftRates } from './prismaDraftContractHelpers'
import { rateRevisionToDomainModel } from './prismaSharedContractRateHelpers'
import type { RateFormEditable } from './updateDraftRate'
import { isEqualData } from '../../resolvers/healthPlanPackage/contractAndRates/resolverHelpers'

// since prisma needs nulls to indicate "remove this field" instead of "ignore this field"
// this function translates undefineds into nulls
function nullify<T>(field: T | undefined): T | null {
if (field === undefined) {
return null
}

return field
}

// since prisma needs nulls to indicate "remove this field" instead of "ignore this field"
// this function translates undefineds into empty arrays
function emptify<T>(field: T[] | undefined): T[] {
if (field === undefined) {
return []
}
return field
}
import { emptify, nullify } from '../prismaDomainAdaptors'

type ContractFormEditable = Partial<ContractFormDataType>

Expand Down
20 changes: 20 additions & 0 deletions services/app-api/src/postgres/prismaDomainAdaptors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// since prisma needs nulls to indicate "remove this field" instead of "ignore this field"
// this function translates undefineds into nulls
function nullify<T>(field: T | undefined): T | null {
if (field === undefined) {
return null
}

return field
}

// since prisma needs nulls to indicate "remove this field" instead of "ignore this field"
// this function translates undefineds into empty arrays
function emptify<T>(field: T[] | undefined): T[] {
if (field === undefined) {
return []
}
return field
}

export { nullify, emptify }
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import type {
PackageStatusType,
RateType,
} from '../../domain-models/contractAndRates'
import type { RateFormEditable } from '../../postgres/contractAndRates/updateDraftRate'

export const SubmissionErrorCodes = ['INCOMPLETE', 'INVALID'] as const
type SubmissionErrorCode = (typeof SubmissionErrorCodes)[number] // iterable union type
Expand Down Expand Up @@ -305,26 +306,6 @@ export function submitHealthPlanPackageResolver(
initialFormData = conversionResult
contractRevisionID = contractWithHistory.revisions[0].id

// If we are submitting a CONTRACT ONLY but it still has rates associated with it, we need to remove those draftRates now
if (
initialFormData.submissionType === 'CONTRACT_ONLY' &&
initialFormData.rateInfos.length > 0
) {
const rateRemovalResult =
await store.updateDraftContractWithRates({
contractID: contractWithHistory.id,
formData: contractWithHistory.draftRevision.formData,
rateFormDatas: [],
})
if (rateRemovalResult instanceof Error) {
const errMessage =
'Failed to remove draft rates from a CONTRACT ONLY submission: ' +
rateRemovalResult.message
logError('submitHealthPlanPackage', errMessage)
setErrorAttributesOnActiveSpan(errMessage, span)
throw new Error(errMessage)
}
}
// Final clean + check of data before submit - parse to state submission
const maybeLocked = parseAndSubmit(initialFormData)

Expand All @@ -338,6 +319,13 @@ export function submitHealthPlanPackageResolver(
}

// Since submit can change the form data, we have to save it again.
// if the rates were removed, we remove them.
let removeRateInfos: RateFormEditable[] | undefined = undefined
if (maybeLocked.rateInfos.length === 0) {
// undefined means ignore rates in updaterDraftContractWithRates, empty array means empty them.
removeRateInfos = []
}

const updateResult = await store.updateDraftContractWithRates({
contractID: input.pkgID,
formData: {
Expand All @@ -364,6 +352,7 @@ export function submitHealthPlanPackageResolver(
}
),
},
rateFormDatas: removeRateInfos,
})
if (updateResult instanceof Error) {
const errMessage = `Failed to update submitted contract info with ID: ${contractRevisionID}; ${updateResult.message}`
Expand All @@ -378,7 +367,7 @@ export function submitHealthPlanPackageResolver(
}

// If there are rates, submit those first
if (initialFormData.rateInfos.length > 0) {
if (contractWithHistory.revisions[0].rateRevisions.length > 0) {
const ratePromises: Promise<Error | RateType>[] = []
contractWithHistory.revisions[0].rateRevisions.forEach(
(rateRev) => {
Expand Down

0 comments on commit b6c4b35

Please sign in to comment.