Skip to content

Commit

Permalink
fix up unsubmittedRate handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mojotalantikite committed Mar 7, 2024
1 parent f97c603 commit 8a08957
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 4 additions & 9 deletions services/app-api/src/postgres/contractAndRates/submitRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -111,7 +106,7 @@ async function submitRate(
create: {
updatedAt: currentDateTime,
updatedByID: submittedByUserID,
updatedReason: submittedReason
updatedReason: submittedReason,
},
},
contractRevisions: {
Expand Down

0 comments on commit 8a08957

Please sign in to comment.