diff --git a/services/app-api/src/postgres/contractAndRates/findRateWithHistory.test.ts b/services/app-api/src/postgres/contractAndRates/findRateWithHistory.test.ts index 5da25b24aa..e48d1400b5 100644 --- a/services/app-api/src/postgres/contractAndRates/findRateWithHistory.test.ts +++ b/services/app-api/src/postgres/contractAndRates/findRateWithHistory.test.ts @@ -9,11 +9,7 @@ import { insertDraftRate } from './insertRate' import { updateDraftRate } from './updateDraftRate' import { unlockRate } from './unlockRate' import { findRateWithHistory } from './findRateWithHistory' -import { - must, - mockInsertContractArgs, - consoleLogFullData, -} from '../../testHelpers' +import { must, mockInsertContractArgs } from '../../testHelpers' import { mockInsertRateArgs } from '../../testHelpers/rateDataMocks' import { findContractWithHistory } from './findContractWithHistory' import type { DraftContractType } from '../../domain-models/contractAndRates/contractTypes' @@ -550,6 +546,7 @@ describe('findRate', () => { const fetchResubmittedRateOne = must( await findRateWithHistory(client, rateIDOne) ) + //console.info(JSON.stringify(fetchResubmittedRateOne, null, ' ')) expect(fetchResubmittedRateOne.revisions).toHaveLength(2) // Expect the earliest submission contract revision to be attached to first submission rate revision expect( diff --git a/services/app-api/src/postgres/contractAndRates/submitContract.ts b/services/app-api/src/postgres/contractAndRates/submitContract.ts index 2f84927575..09ec525236 100644 --- a/services/app-api/src/postgres/contractAndRates/submitContract.ts +++ b/services/app-api/src/postgres/contractAndRates/submitContract.ts @@ -39,9 +39,12 @@ export async function submitContract( console.error(err) return new NotFoundError(err) } - //console.info(`current rev : ${JSON.stringify(currentRev, null, ' ')}`) + // get the related rate revisions and any unsubmitted rates const relatedRateRevs = currentRev.draftRates.map((c) => c.revisions[0]) + const unsubmittedRates = relatedRateRevs.filter( + (rev) => rev.submitInfo === null + ) return await client.$transaction(async (tx) => { // Create the submitInfo record in the updateInfoTable @@ -91,7 +94,8 @@ export async function submitContract( }, }) - for (const rev of relatedRateRevs) { + // we only want to update the rateRevision's submit info if it has not already been submitted + for (const rev of unsubmittedRates) { await tx.rateRevisionTable.update({ where: { id: rev.id, diff --git a/services/app-api/src/postgres/contractAndRates/submitRate.ts b/services/app-api/src/postgres/contractAndRates/submitRate.ts index 0a06068d43..20645367fd 100644 --- a/services/app-api/src/postgres/contractAndRates/submitRate.ts +++ b/services/app-api/src/postgres/contractAndRates/submitRate.ts @@ -7,7 +7,7 @@ import { includeLatestSubmittedRateRev } from './prismaSubmittedContractHelpers' import { NotFoundError } from '../postgresErrors' import type { RateFormDataType } from '../../domain-models' -type SubmitRateArgsType = { +type SubmitRateArgsType = { rateID?: string rateRevisionID?: string // this is a hack that should not outlive protobuf. rateID should be there and be required after we remove protos formData?: RateFormDataType @@ -26,14 +26,9 @@ async function submitRate( try { return await client.$transaction(async (tx) => { - const { - rateID, - rateRevisionID, - submittedByUserID, - formData, - } = args + const { rateID, rateRevisionID, submittedByUserID, formData } = args - const submittedReason = args.submittedReason ?? 'Initial submission' // all subsequent submissions will have a submit reason due to unlock submit modal + const submittedReason = args.submittedReason ?? 'Initial submission' // all subsequent submissions will have a submit reason due to unlock submit modal // this is a hack that should not outlive protobuf. Protobufs only have // rate revision IDs in them, so we allow submitting by rate revisionID from our submitHPP resolver @@ -111,7 +106,7 @@ async function submitRate( create: { updatedAt: currentDateTime, updatedByID: submittedByUserID, - updatedReason: submittedReason + updatedReason: submittedReason, }, }, contractRevisions: {