diff --git a/services/app-api/prisma/migrations/20230808082415_drop_rate_name/migration.sql b/services/app-api/prisma/migrations/20230808082415_drop_rate_name/migration.sql new file mode 100644 index 0000000000..eb9271b7d8 --- /dev/null +++ b/services/app-api/prisma/migrations/20230808082415_drop_rate_name/migration.sql @@ -0,0 +1,10 @@ +BEGIN; +/* + Warnings: + + - You are about to drop the column `name` on the `RateRevisionTable` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "RateRevisionTable" DROP COLUMN "name"; +COMMIT; diff --git a/services/app-api/prisma/schema.prisma b/services/app-api/prisma/schema.prisma index e3ffbe5692..e5c84804ed 100644 --- a/services/app-api/prisma/schema.prisma +++ b/services/app-api/prisma/schema.prisma @@ -124,7 +124,6 @@ model RateRevisionTable { submitInfoID String? submitInfo UpdateInfoTable? @relation("submitRateInfo", fields: [submitInfoID], references: [id]) - name String rateType RateType? rateCapitationType RateCapitationType? rateDocuments RateDocument[] diff --git a/services/app-api/src/domain-models/contractAndRates/contractAndRatesZodSchema.ts b/services/app-api/src/domain-models/contractAndRates/contractAndRatesZodSchema.ts index f81332dee5..0eff023818 100644 --- a/services/app-api/src/domain-models/contractAndRates/contractAndRatesZodSchema.ts +++ b/services/app-api/src/domain-models/contractAndRates/contractAndRatesZodSchema.ts @@ -1,9 +1,14 @@ import { z } from 'zod' import { + actuaryCommunicationTypeSchema, + actuaryContactSchema, contractExecutionStatusSchema, contractTypeSchema, federalAuthoritySchema, populationCoveredSchema, + rateCapitationTypeSchema, + rateTypeSchema, + sharedRateCertDisplay, stateContactSchema, submissionDocumentSchema, submissionTypeSchema, @@ -58,21 +63,50 @@ const contractRevisionSchema = z.object({ formData: contractFormDataSchema, }) +// The rate form data is the form filled out by state users submitting rates for review +const rateFormDataSchema = z.object({ + id: z.string().optional(), + rateType: rateTypeSchema.optional(), + rateCapitationType: rateCapitationTypeSchema.optional(), + rateDocuments: z.array(submissionDocumentSchema).optional(), + supportingDocuments: z.array(submissionDocumentSchema).optional(), + rateDateStart: z.date().optional(), + rateDateEnd: z.date().optional(), + rateDateCertified: z.date().optional(), + amendmentEffectiveDateStart: z.date().optional(), + amendmentEffectiveDateEnd: z.date().optional(), + rateProgramIDs: z.array(z.string()).optional(), + rateCertificationName: z.string().optional(), + certifyingActuaryContacts: z.array(actuaryContactSchema).optional(), + addtlActuaryContacts: z.array(actuaryContactSchema).optional(), + actuaryCommunicationPreference: actuaryCommunicationTypeSchema.optional(), + packagesWithSharedRateCerts: z.array(sharedRateCertDisplay).optional(), +}) + +// A Rate represents all the data associated with a single rate certification over time. +// The rate's revisions field hold the array of rate revisions that show change history of specific rate data +// The first revision (array index 0) is the current revision const ratesRevisionSchema = z.object({ id: z.string().uuid(), submitInfo: updateInfoSchema.optional(), unlockInfo: updateInfoSchema.optional(), - revisionFormData: z.string(), + createdAt: z.date(), + updatedAt: z.date(), + revisionFormData: rateFormDataSchema, }) // ContractRevision has all the information in a single submission of this contract. // If a revision has been submitted it will have submitInfo (otherwise it will be a draft) // if a revision was unlocked, it will have unlock info, otherwise it was an initial submission // The set of rateRevisions hold exactly what rate data was present at the time this contract was submitted. -const contractRevisionZodSchema = contractRevisionSchema.extend({ +const contractRevisionWithRatesSchema = contractRevisionSchema.extend({ rateRevisions: z.array(ratesRevisionSchema), }) +const rateRevisionWithContractsSchema = ratesRevisionSchema.extend({ + contractRevisions: z.array(contractRevisionSchema), +}) + // Contract represents the contract specific information in a submission package // All that data is contained in revisions, each revision represents the data in a single submission // submissions are kept intact here across time @@ -81,58 +115,54 @@ const contractZodSchema = z.object({ status: z.union([z.literal('SUBMITTED'), z.literal('DRAFT')]), stateCode: z.string(), stateNumber: z.number().min(1), - revisions: z.array(contractRevisionZodSchema), + revisions: z.array(contractRevisionWithRatesSchema), }) const draftContractZodSchema = contractZodSchema.extend({ status: z.literal('DRAFT'), - revisions: z.array(contractRevisionZodSchema).min(1), + revisions: z.array(contractRevisionWithRatesSchema).min(1), +}) + +const rateZodSchema = z.object({ + id: z.string().uuid(), + status: z.union([z.literal('SUBMITTED'), z.literal('DRAFT')]), + stateCode: z.string(), + stateNumber: z.number().min(1), + revisions: z.array(rateRevisionWithContractsSchema), }) -type ContractFormDataType = z.infer type ContractType = z.infer -type ContractRevisionType = z.infer +type ContractRevisionType = z.infer +type ContractRevisionWithRatesType = z.infer< + typeof contractRevisionWithRatesSchema +> +type ContractFormDataType = z.infer + +type RateType = z.infer +type RateRevisionType = z.infer +type RateRevisionWithContractsType = z.infer< + typeof rateRevisionWithContractsSchema +> +type RateFormDataType = z.infer + type UpdateInfoType = z.infer type ContractStatusType = z.infer -export { contractRevisionZodSchema, draftContractZodSchema, contractZodSchema } +export { + contractRevisionWithRatesSchema, + draftContractZodSchema, + contractZodSchema, +} export type { - ContractFormDataType, ContractType, ContractRevisionType, + ContractRevisionWithRatesType, + ContractFormDataType, + RateType, + RateRevisionType, + RateRevisionWithContractsType, + RateFormDataType, UpdateInfoType, ContractStatusType, } - -/// Returned By FindWithHistory, Submit -// ContractWithRevisionsType -// - ContractType -// - revisions: ContractRevisionWithRateRevisionsType -// -- ContractRevisionType -// -- ContractFormDataType -// -- rateRevisions: RateRevisionType -// ---RateFormDataType -// --- rate: RateType - -// returned by insertContract, unlockContract?, updateContract, -// DraftContractType -// - ContractType -// - draftRevision: DraftContractRevisionType -// -- ContractRevisionType -// -- ContractFormDataType -// -- rateRevisions: RateRevisionType -// --- RateFormDataType -// --- rate: RateType - -// ContractType -// ContractWithRevisionsType -// ContractRevisionType -// ContractRevisionWithRateRevisionsType -// ContractFormDataType - -// RateType -// RateWithRevisionsType -// RateRevisonType -// RateRevisionWithContractRevisionsType -// RateFormDataType diff --git a/services/app-api/src/domain-models/contractAndRates/parseDomainData.test.ts b/services/app-api/src/domain-models/contractAndRates/parseDomainData.test.ts index c011e9d05f..fc972dc8f9 100644 --- a/services/app-api/src/domain-models/contractAndRates/parseDomainData.test.ts +++ b/services/app-api/src/domain-models/contractAndRates/parseDomainData.test.ts @@ -2,7 +2,7 @@ import { DraftContractTableWithRelations, DraftContractRevisionTableWithRelations, ContractTableWithRelations, - ContractRevisionTableWithRelations, + ContractRevisionTableWithRates, } from '../../postgres/prismaTypes' import { parseDraftContract, @@ -177,12 +177,15 @@ describe('parseDomainData', () => { submitInfo: null, unlockInfo: null, unlockInfoID: null, - name: 'some data', rateType: null, rateCapitationType: null, rateDateStart: null, rateDateEnd: null, rateDateCertified: null, + rateDocuments: [], + certifyingActuaryContacts: [], + addtlActuaryContacts: [], + supportingDocuments: [], amendmentEffectiveDateStart: null, amendmentEffectiveDateEnd: null, rateProgramIDs: [], @@ -191,7 +194,7 @@ describe('parseDomainData', () => { }, }, ], - }) as ContractRevisionTableWithRelations, + }) as ContractRevisionTableWithRates, ], }), testDescription: 'unsubmitted rate', diff --git a/services/app-api/src/domain-models/contractAndRates/parseDomainData.ts b/services/app-api/src/domain-models/contractAndRates/parseDomainData.ts index 23f2c629e6..3ea7246140 100644 --- a/services/app-api/src/domain-models/contractAndRates/parseDomainData.ts +++ b/services/app-api/src/domain-models/contractAndRates/parseDomainData.ts @@ -4,9 +4,9 @@ import { } from '../../postgres/prismaTypes' import { ContractType, - ContractRevisionType, - contractRevisionZodSchema, draftContractZodSchema, + contractRevisionWithRatesSchema, + ContractRevisionWithRatesType, } from './contractAndRatesZodSchema' import { draftContractToDomainModel, @@ -15,9 +15,9 @@ import { function parseDraftContractRevision( revision: DraftContractRevisionTableWithRelations -): ContractRevisionType | Error { +): ContractRevisionWithRatesType | Error { const draftContractRevision = draftContractRevToDomainModel(revision) - const parseDraft = contractRevisionZodSchema.safeParse( + const parseDraft = contractRevisionWithRatesSchema.safeParse( draftContractRevision ) diff --git a/services/app-api/src/domain-models/contractAndRates/rateType.ts b/services/app-api/src/domain-models/contractAndRates/rateType.ts deleted file mode 100644 index 82c6882783..0000000000 --- a/services/app-api/src/domain-models/contractAndRates/rateType.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - ContractRevisionType, - UpdateInfoType, -} from './contractAndRatesZodSchema' - -// Rate represents the rate specific information in a submission package -// All that data is contained in revisions, each revision represents the data in a single submission -// submissions are kept intact here across time -interface Rate { - id: string - revisions: RateRevision[] -} - -// RateRevision has all the information in a single submission of this rate. -// If a revision has been submitted it will have submitInfo (otherwise it will be a draft) -// if a revision was unlocked, it will have unlock info, otherwise it was an initial submission -// The set of contractRevisions hold exactly what contract data was present at the time this rate was submitted. -interface RateRevision { - id: string - unlockInfo?: UpdateInfoType - submitInfo?: UpdateInfoType - - revisionFormData: string - contractRevisions?: ContractRevisionType[] -} - -export type { Rate, RateRevision } diff --git a/services/app-api/src/postgres/contractAndRates/findContractWithHistory.test.ts b/services/app-api/src/postgres/contractAndRates/findContractWithHistory.test.ts index c01208f53d..300c9c97ae 100644 --- a/services/app-api/src/postgres/contractAndRates/findContractWithHistory.test.ts +++ b/services/app-api/src/postgres/contractAndRates/findContractWithHistory.test.ts @@ -57,7 +57,7 @@ describe('findContract', () => { const rate1 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'someurle.en', + rateCertificationName: 'someurle.en', }) ) must( @@ -70,7 +70,7 @@ describe('findContract', () => { const rate2 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'twopointo', + rateCertificationName: 'twopointo', }) ) must( @@ -81,7 +81,7 @@ describe('findContract', () => { const rate3 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'threepointo', + rateCertificationName: 'threepointo', }) ) must( @@ -263,9 +263,10 @@ describe('findContract', () => { ) expect(revisionsInTimeOrder[5].rateRevisions).toHaveLength(2) - expect(revisionsInTimeOrder[5].rateRevisions[1].revisionFormData).toBe( - 'onepointone' - ) + expect( + revisionsInTimeOrder[5].rateRevisions[1].revisionFormData + .rateCertificationName + ).toBe('onepointone') expect(revisionsInTimeOrder[5].unlockInfo?.updatedReason).toBe( 'unlock for 1.1' ) @@ -346,7 +347,7 @@ describe('findContract', () => { const rate1 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'someurle.en', + rateCertificationName: 'someurle.en', }) ) must( @@ -359,7 +360,7 @@ describe('findContract', () => { const rate2 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'twopointo', + rateCertificationName: 'twopointo', }) ) must( @@ -370,7 +371,7 @@ describe('findContract', () => { const rate3 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'threepointo', + rateCertificationName: 'threepointo', }) ) must( @@ -483,9 +484,9 @@ describe('findContract', () => { expect(revisions[4].rateRevisions).toHaveLength(2) expect(revisions[5].rateRevisions).toHaveLength(2) - expect(revisions[5].rateRevisions[1].revisionFormData).toBe( - 'onepointone' - ) + expect( + revisions[5].rateRevisions[1].revisionFormData.rateCertificationName + ).toBe('onepointone') expect(revisions[5].submitInfo?.updatedReason).toBe('1.1 new name') expect(revisions[6].rateRevisions).toHaveLength(2) @@ -541,7 +542,7 @@ describe('findContract', () => { const rate1 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'onepoint0', + rateCertificationName: 'onepoint0', }) ) must(await updateDraftRate(client, rate1.id, 'onepoint0', [])) @@ -550,7 +551,7 @@ describe('findContract', () => { const rate2 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'twopointo', + rateCertificationName: 'twopointo', }) ) must(await updateDraftRate(client, rate2.id, 'twopointo', [])) @@ -648,7 +649,9 @@ describe('findContract', () => { // these revisions can be in any order because they were saved at the same time const revisionFormDatas = new Set( - revisions[2].rateRevisions.map((rr) => rr.revisionFormData) + revisions[2].rateRevisions.map( + (rr) => rr.revisionFormData.rateCertificationName + ) ) const expectedFormDatas = new Set(['onepoint0', 'twopointone']) expect(revisionFormDatas).toStrictEqual(expectedFormDatas) diff --git a/services/app-api/src/postgres/contractAndRates/findContractWithHistory.ts b/services/app-api/src/postgres/contractAndRates/findContractWithHistory.ts index f9b207b846..37609b0286 100644 --- a/services/app-api/src/postgres/contractAndRates/findContractWithHistory.ts +++ b/services/app-api/src/postgres/contractAndRates/findContractWithHistory.ts @@ -2,6 +2,7 @@ import { PrismaTransactionType } from '../prismaTypes' import { ContractType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' import { updateInfoIncludeUpdater } from '../prismaHelpers' import { NotFoundError } from '../storeError' +import { parseContractWithHistory } from './prismaContractWithHistoryConverter' // findContractWithHistory returns a ContractType with a full set of // ContractRevisions in reverse chronological order. Each revision is a change to this @@ -28,8 +29,13 @@ async function findContractWithHistory( include: { rateRevision: { include: { + rateDocuments: true, + supportingDocuments: true, + certifyingActuaryContacts: true, + addtlActuaryContacts: true, submitInfo: updateInfoIncludeUpdater, unlockInfo: updateInfoIncludeUpdater, + draftContracts: true, }, }, }, diff --git a/services/app-api/src/postgres/contractAndRates/findDraftContract.test.ts b/services/app-api/src/postgres/contractAndRates/findDraftContract.test.ts index 20e77e71ef..7d90aab09e 100644 --- a/services/app-api/src/postgres/contractAndRates/findDraftContract.test.ts +++ b/services/app-api/src/postgres/contractAndRates/findDraftContract.test.ts @@ -30,7 +30,7 @@ describe('findDraftContract', () => { const rate1 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'onepoint0', + rateCertificationName: 'onepoint0', }) ) must(await updateDraftRate(client, rate1.id, 'onepoint0', [])) @@ -39,7 +39,7 @@ describe('findDraftContract', () => { const rate2 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'twopointo', + rateCertificationName: 'twopointo', }) ) must(await updateDraftRate(client, rate2.id, 'twopointo', [])) @@ -106,7 +106,7 @@ describe('findDraftContract', () => { const rate1 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'onepoint0', + rateCertificationName: 'onepoint0', }) ) must(await updateDraftRate(client, rate1.id, 'onepoint0', [])) @@ -165,7 +165,9 @@ describe('findDraftContract', () => { expect(draft).toBeDefined() expect(draft.rateRevisions).toHaveLength(1) - expect(draft.rateRevisions[0].revisionFormData).toBe('draft two') + expect( + draft.rateRevisions[0].revisionFormData.rateCertificationName + ).toBe('draft two') }) it('works on a later revision', async () => { diff --git a/services/app-api/src/postgres/contractAndRates/findDraftContract.ts b/services/app-api/src/postgres/contractAndRates/findDraftContract.ts index 08baeb70cd..1066697235 100644 --- a/services/app-api/src/postgres/contractAndRates/findDraftContract.ts +++ b/services/app-api/src/postgres/contractAndRates/findDraftContract.ts @@ -1,5 +1,5 @@ import { PrismaClient } from '@prisma/client' -import { ContractRevisionType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' +import { ContractRevisionWithRatesType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' import { parseDraftContractRevision } from '../../domain-models/contractAndRates/parseDomainData' import { draftContractRevisionsWithDraftRates } from '../prismaHelpers' @@ -7,7 +7,7 @@ import { draftContractRevisionsWithDraftRates } from '../prismaHelpers' async function findDraftContract( client: PrismaClient, contractID: string -): Promise { +): Promise { try { const draftContractRevision = await client.contractRevisionTable.findFirst({ diff --git a/services/app-api/src/postgres/contractAndRates/findDraftRate.test.ts b/services/app-api/src/postgres/contractAndRates/findDraftRate.test.ts index 8638cf8e07..c9aea0c806 100644 --- a/services/app-api/src/postgres/contractAndRates/findDraftRate.test.ts +++ b/services/app-api/src/postgres/contractAndRates/findDraftRate.test.ts @@ -12,7 +12,7 @@ describe('findDraftRate', () => { const rate1 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'onepoint0', + rateCertificationName: 'onepoint0', }) ) must(await updateDraftRate(client, rate1.id, 'draftData', [])) @@ -23,6 +23,6 @@ describe('findDraftRate', () => { throw draft } - expect(draft?.revisionFormData).toBe('draftData') + expect(draft?.revisionFormData.rateCertificationName).toBe('draftData') }) }) diff --git a/services/app-api/src/postgres/contractAndRates/findDraftRate.ts b/services/app-api/src/postgres/contractAndRates/findDraftRate.ts index 31175a2dd6..2691e10301 100644 --- a/services/app-api/src/postgres/contractAndRates/findDraftRate.ts +++ b/services/app-api/src/postgres/contractAndRates/findDraftRate.ts @@ -1,13 +1,16 @@ import { PrismaClient } from '@prisma/client' -import { RateRevision } from '../../domain-models/contractAndRates/rateType' -import { contractFormDataToDomainModel } from './prismaToDomainModel' +import { + contractFormDataToDomainModel, + rateFormDataToDomainModel, +} from './prismaToDomainModel' import { updateInfoIncludeUpdater } from '../prismaHelpers' +import { RateRevisionWithContractsType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' // findDraftRate returns a draft (if any) for the given contract. async function findDraftRate( client: PrismaClient, rateID: string -): Promise { +): Promise { try { const draftRate = await client.rateRevisionTable.findFirst({ where: { @@ -17,6 +20,10 @@ async function findDraftRate( include: { submitInfo: updateInfoIncludeUpdater, unlockInfo: updateInfoIncludeUpdater, + rateDocuments: true, + supportingDocuments: true, + certifyingActuaryContacts: true, + addtlActuaryContacts: true, draftContracts: { include: { revisions: { @@ -49,19 +56,18 @@ async function findDraftRate( return undefined } - const draft: RateRevision = { + const draft: RateRevisionWithContractsType = { id: draftRate.id, - revisionFormData: draftRate.name, + createdAt: draftRate.createdAt, + updatedAt: draftRate.updatedAt, + + revisionFormData: rateFormDataToDomainModel(draftRate), contractRevisions: draftRate.draftContracts.map((dc) => ({ id: dc.revisions[0].id, createdAt: dc.revisions[0].createdAt, updatedAt: dc.revisions[0].updatedAt, formData: contractFormDataToDomainModel(dc.revisions[0]), - rateRevisions: dc.revisions[0].rateRevisions.map((rr) => ({ - id: rr.rateRevisionID, - revisionFormData: rr.rateRevision.name, - })), })), } diff --git a/services/app-api/src/postgres/contractAndRates/findRateWithHistory.test.ts b/services/app-api/src/postgres/contractAndRates/findRateWithHistory.test.ts index 8d42819564..2352fbe196 100644 --- a/services/app-api/src/postgres/contractAndRates/findRateWithHistory.test.ts +++ b/services/app-api/src/postgres/contractAndRates/findRateWithHistory.test.ts @@ -56,7 +56,7 @@ describe('findContract', () => { const rate1 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'someurle.en', + rateCertificationName: 'someurle.en', }) ) must( @@ -69,7 +69,7 @@ describe('findContract', () => { const rate2 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'twopointo', + rateCertificationName: 'twopointo', }) ) must( @@ -80,7 +80,7 @@ describe('findContract', () => { const rate3 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'threepointo', + rateCertificationName: 'threepointo', }) ) must( diff --git a/services/app-api/src/postgres/contractAndRates/findRateWithHistory.ts b/services/app-api/src/postgres/contractAndRates/findRateWithHistory.ts index 9f92559253..cb3ebd5326 100644 --- a/services/app-api/src/postgres/contractAndRates/findRateWithHistory.ts +++ b/services/app-api/src/postgres/contractAndRates/findRateWithHistory.ts @@ -1,29 +1,33 @@ -import { RateRevisionTable, UpdateInfoTable, User } from '@prisma/client' -import { PrismaTransactionType } from '../prismaTypes' +import { UpdateInfoTable, User } from '@prisma/client' import { - Rate, - RateRevision, -} from '../../domain-models/contractAndRates/rateType' + PrismaTransactionType, + RateRevisionTableWithFormData, +} from '../prismaTypes' import { contractFormDataToDomainModel, convertUpdateInfoToDomainModel, + rateFormDataToDomainModel, } from './prismaToDomainModel' -import { ContractRevisionTableWithRelations } from '../prismaTypes' +import { ContractRevisionTableWithFormData } from '../prismaTypes' import { updateInfoIncludeUpdater } from '../prismaHelpers' +import { + RateRevisionWithContractsType, + RateType, +} from '../../domain-models/contractAndRates/contractAndRatesZodSchema' // this is for the internal building of individual revisions // we convert them into RateRevisons to return them interface RateRevisionSet { - rateRev: RateRevisionTable + rateRev: RateRevisionTableWithFormData submitInfo: UpdateInfoTable & { updatedBy: User } unlockInfo: (UpdateInfoTable & { updatedBy: User }) | undefined - contractRevs: ContractRevisionTableWithRelations[] + contractRevs: ContractRevisionTableWithFormData[] } async function findRateWithHistory( client: PrismaTransactionType, rateID: string -): Promise { +): Promise { try { const rateRevisions = await client.rateRevisionTable.findMany({ where: { @@ -35,6 +39,11 @@ async function findRateWithHistory( include: { submitInfo: updateInfoIncludeUpdater, unlockInfo: updateInfoIncludeUpdater, + rateDocuments: true, + supportingDocuments: true, + certifyingActuaryContacts: true, + addtlActuaryContacts: true, + draftContracts: true, contractRevisions: { include: { contractRevision: { @@ -44,11 +53,6 @@ async function findRateWithHistory( stateContacts: true, contractDocuments: true, supportingDocuments: true, - rateRevisions: { - include: { - rateRevision: true, - }, - }, }, }, }, @@ -124,29 +128,34 @@ async function findRateWithHistory( } } - const allRevisions: RateRevision[] = allEntries.map((entry) => ({ - id: entry.rateRev.id, - submitInfo: convertUpdateInfoToDomainModel(entry.submitInfo), - unlockInfo: - entry.unlockInfo && - convertUpdateInfoToDomainModel(entry.unlockInfo), - revisionFormData: entry.rateRev.name, - contractRevisions: entry.contractRevs.map((crev) => ({ - id: crev.id, - createdAt: crev.createdAt, - updatedAt: crev.updatedAt, - formData: contractFormDataToDomainModel(crev), - rateRevisions: crev.rateRevisions.map((rr) => ({ - id: rr.rateRevisionID, - revisionFormData: rr.rateRevision.name, + const allRevisions: RateRevisionWithContractsType[] = allEntries.map( + (entry) => ({ + id: entry.rateRev.id, + createdAt: entry.rateRev.createdAt, + updatedAt: entry.rateRev.updatedAt, + submitInfo: convertUpdateInfoToDomainModel(entry.submitInfo), + unlockInfo: + entry.unlockInfo && + convertUpdateInfoToDomainModel(entry.unlockInfo), + revisionFormData: rateFormDataToDomainModel(entry.rateRev), + contractRevisions: entry.contractRevs.map((crev) => ({ + id: crev.id, + createdAt: crev.createdAt, + updatedAt: crev.updatedAt, + formData: contractFormDataToDomainModel(crev), })), - })), - })) + }) + ) - return { + const finalRate: RateType = { id: rateID, + status: 'SUBMITTED', + stateCode: 'MN', + stateNumber: 4, revisions: allRevisions.reverse(), } + + return finalRate } catch (err) { console.error('PRISMA ERROR', err) return err diff --git a/services/app-api/src/postgres/contractAndRates/index.ts b/services/app-api/src/postgres/contractAndRates/index.ts index a19f8dabd8..cc70bf16ac 100644 --- a/services/app-api/src/postgres/contractAndRates/index.ts +++ b/services/app-api/src/postgres/contractAndRates/index.ts @@ -6,10 +6,7 @@ import { convertUpdateInfoToDomainModel, draftContractRevToDomainModel, draftContractToDomainModel, - contractRevToDomainModel, draftRatesToDomainModel, - ratesRevisionsToDomainModel, - contractWithHistoryToDomainModel, getContractStatus, } from './prismaToDomainModel' @@ -21,10 +18,7 @@ export { convertUpdateInfoToDomainModel, draftContractRevToDomainModel, draftContractToDomainModel, - contractRevToDomainModel, draftRatesToDomainModel, - ratesRevisionsToDomainModel, - contractWithHistoryToDomainModel, getContractStatus, } diff --git a/services/app-api/src/postgres/contractAndRates/insertRate.ts b/services/app-api/src/postgres/contractAndRates/insertRate.ts index 3fac412487..e94a6afd49 100644 --- a/services/app-api/src/postgres/contractAndRates/insertRate.ts +++ b/services/app-api/src/postgres/contractAndRates/insertRate.ts @@ -1,17 +1,62 @@ -import { PrismaClient } from '@prisma/client' -import { Rate } from '../../domain-models/contractAndRates/rateType' -import { contractFormDataToDomainModel } from './prismaToDomainModel' +import { + ActuaryCommunication, + ActuaryContact, + PrismaClient, + RateCapitationType, + RateDocument, + RateSupportingDocument, +} from '@prisma/client' +import { + StateCodeType, + RateType as DomainRateType, +} from 'app-web/src/common-code/healthPlanFormDataType' +import { RateType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' +import { + contractFormDataToDomainModel, + rateFormDataToDomainModel, +} from './prismaToDomainModel' type InsertRateArgsType = { - stateCode: string - name: string + stateCode: StateCodeType + rateType?: DomainRateType + rateCapitationType?: RateCapitationType + rateDocuments?: RateDocument[] + supportingDocuments?: RateSupportingDocument[] + rateDateStart?: Date + rateDateEnd?: Date + rateDateCertified?: Date + amendmentEffectiveDateStart?: Date + amendmentEffectiveDateEnd?: Date + rateProgramIDs?: string[] + rateCertificationName?: string + certifyingActuaryContacts?: ActuaryContact[] + addtlActuaryContacts?: ActuaryContact[] + actuaryCommunicationPreference?: ActuaryCommunication } // creates a new contract, with a new revision async function insertDraftRate( client: PrismaClient, args: InsertRateArgsType -): Promise { +): Promise { + const { + stateCode, + rateType, + rateCapitationType, + rateDocuments, + supportingDocuments, + rateDateStart, + rateDateEnd, + rateDateCertified, + amendmentEffectiveDateStart, + amendmentEffectiveDateEnd, + rateProgramIDs, + rateCertificationName, + certifyingActuaryContacts, + addtlActuaryContacts, + actuaryCommunicationPreference, + } = args + try { return await client.$transaction(async (tx) => { const { latestStateRateCertNumber } = await tx.state.update({ @@ -27,26 +72,47 @@ async function insertDraftRate( const rate = await tx.rateTable.create({ data: { - stateCode: args.stateCode, + stateCode: stateCode, stateNumber: latestStateRateCertNumber, revisions: { create: { - name: args.name, + rateType, + rateCapitationType: rateCapitationType, + rateDocuments: { + create: rateDocuments, + }, + supportingDocuments: { + create: supportingDocuments, + }, + rateDateStart, + rateDateEnd, + rateDateCertified, + amendmentEffectiveDateStart, + amendmentEffectiveDateEnd, + rateProgramIDs, + rateCertificationName, + certifyingActuaryContacts: { + create: certifyingActuaryContacts, + }, + addtlActuaryContacts: { + create: addtlActuaryContacts, + }, + actuaryCommunicationPreference, }, }, }, include: { revisions: { include: { + rateDocuments: true, + supportingDocuments: true, + certifyingActuaryContacts: true, + addtlActuaryContacts: true, + draftContracts: true, contractRevisions: { include: { contractRevision: { include: { - rateRevisions: { - include: { - rateRevision: true, - }, - }, stateContacts: true, contractDocuments: true, supportingDocuments: true, @@ -59,11 +125,17 @@ async function insertDraftRate( }, }) - return { + const finalRate: RateType = { id: rate.id, + status: 'DRAFT', + stateCode: rate.stateCode, + stateNumber: rate.stateNumber, revisions: rate.revisions.map((rr) => ({ id: rr.id, - revisionFormData: rr.name, + createdAt: rr.createdAt, + updatedAt: rr.updatedAt, + revisionFormData: rateFormDataToDomainModel(rr), + contractRevisions: rr.contractRevisions.map( ({ contractRevision }) => ({ id: contractRevision.id, @@ -76,6 +148,7 @@ async function insertDraftRate( ), })), } + return finalRate }) } catch (err) { console.error('RATE PRISMA ERR', err) diff --git a/services/app-api/src/postgres/contractAndRates/prismaContractWithHistoryConverter.ts b/services/app-api/src/postgres/contractAndRates/prismaContractWithHistoryConverter.ts index d0e5658538..08626f97cc 100644 --- a/services/app-api/src/postgres/contractAndRates/prismaContractWithHistoryConverter.ts +++ b/services/app-api/src/postgres/contractAndRates/prismaContractWithHistoryConverter.ts @@ -1,12 +1,12 @@ -import { RateRevisionTable } from '@prisma/client' import { ContractType, - ContractRevisionType, contractZodSchema, + ContractRevisionWithRatesType, } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' import { - ContractRevisionTableWithRelations, + ContractRevisionTableWithRates, ContractTableWithRelations, + RateRevisionTableWithFormData, UpdateInfoTableWithUpdater, } from '../prismaTypes' import { @@ -47,15 +47,15 @@ function parseContractWithHistory( // ContractRevisionSet is for the internal building of individual revisions // we convert them into ContractRevisions to return them interface ContractRevisionSet { - contractRev: ContractRevisionTableWithRelations + contractRev: ContractRevisionTableWithRates submitInfo: UpdateInfoTableWithUpdater unlockInfo: UpdateInfoTableWithUpdater | undefined - rateRevisions: RateRevisionTable[] + rateRevisions: RateRevisionTableWithFormData[] } function contractRevToDomainModel( revisions: ContractRevisionSet[] -): ContractRevisionType[] { +): ContractRevisionWithRatesType[] { const contractRevisions = revisions.map((entry) => ({ id: entry.contractRev.id, submitInfo: convertUpdateInfoToDomainModel(entry.submitInfo), diff --git a/services/app-api/src/postgres/contractAndRates/prismaToDomainModel.test.ts b/services/app-api/src/postgres/contractAndRates/prismaToDomainModel.test.ts index 7c71b3ec1e..7602df87c8 100644 --- a/services/app-api/src/postgres/contractAndRates/prismaToDomainModel.test.ts +++ b/services/app-api/src/postgres/contractAndRates/prismaToDomainModel.test.ts @@ -4,7 +4,7 @@ import { } from './prismaToDomainModel' import { ContractRevisionFormDataType, - ContractRevisionTableWithRelations, + ContractRevisionTableWithRates, } from '../prismaTypes' import { v4 as uuidv4 } from 'uuid' import { createContractRevision } from '../../testHelpers' @@ -56,7 +56,7 @@ describe('prismaToDomainModel', () => { describe('getContractStatus', () => { const contractWithUnorderedRevs: { revision: Pick< - ContractRevisionTableWithRelations, + ContractRevisionTableWithRates, 'createdAt' | 'submitInfo' >[] testDescription: string diff --git a/services/app-api/src/postgres/contractAndRates/prismaToDomainModel.ts b/services/app-api/src/postgres/contractAndRates/prismaToDomainModel.ts index bb0fd7d72b..0e91a44778 100644 --- a/services/app-api/src/postgres/contractAndRates/prismaToDomainModel.ts +++ b/services/app-api/src/postgres/contractAndRates/prismaToDomainModel.ts @@ -1,21 +1,22 @@ import { ContractType, - ContractRevisionType, ContractFormDataType, ContractStatusType, + RateRevisionType, + ContractRevisionWithRatesType, + RateFormDataType, } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' -import { RateRevision } from '../../domain-models/contractAndRates/rateType' import { DraftContractRevisionTableWithRelations, DraftContractTableWithRelations, UpdateInfoTableWithUpdater, DraftRateWithRelations, - ContractRevisionTableWithRelations, + ContractRevisionTableWithRates, ContractRevisionFormDataType, + RateRevisionTableWithFormData, } from '../prismaTypes' import { UpdateInfoType } from '../../domain-models' import { DocumentCategoryType } from 'app-web/src/common-code/healthPlanFormDataType' -import { RateRevisionTable } from '@prisma/client' function convertUpdateInfoToDomainModel( info?: UpdateInfoTableWithUpdater | null @@ -32,10 +33,7 @@ function convertUpdateInfoToDomainModel( } function getContractStatus( - revision: Pick< - ContractRevisionTableWithRelations, - 'createdAt' | 'submitInfo' - >[] + revision: Pick[] ): ContractStatusType { // need to order revisions from latest to earliest const latestToEarliestRev = revision.sort( @@ -125,27 +123,90 @@ function contractFormDataToDomainModel( } } +const rateFormDataToDomainModel = ( + rateRevision: RateRevisionTableWithFormData +): RateFormDataType => { + return { + id: rateRevision.id, + rateType: rateRevision.rateType ?? undefined, + rateCapitationType: rateRevision.rateCapitationType ?? undefined, + rateDocuments: rateRevision.rateDocuments + ? rateRevision.rateDocuments.map((doc) => ({ + name: doc.name, + s3URL: doc.s3URL, + sha256: doc.sha256 ?? undefined, + documentCategories: ['RATES'] as DocumentCategoryType[], + })) + : [], + supportingDocuments: rateRevision.supportingDocuments + ? rateRevision.supportingDocuments.map((doc) => ({ + name: doc.name, + s3URL: doc.s3URL, + sha256: doc.sha256 ?? undefined, + documentCategories: [ + 'RATES_RELATED', + ] as DocumentCategoryType[], + })) + : [], + rateDateStart: rateRevision.rateDateStart ?? undefined, + rateDateEnd: rateRevision.rateDateEnd ?? undefined, + rateDateCertified: rateRevision.rateDateCertified ?? undefined, + amendmentEffectiveDateStart: + rateRevision.amendmentEffectiveDateStart ?? undefined, + amendmentEffectiveDateEnd: + rateRevision.amendmentEffectiveDateEnd ?? undefined, + rateProgramIDs: rateRevision.rateProgramIDs, + rateCertificationName: rateRevision.rateCertificationName ?? undefined, + certifyingActuaryContacts: rateRevision.certifyingActuaryContacts + ? rateRevision.certifyingActuaryContacts.map((actuary) => ({ + name: actuary.name, + titleRole: actuary.titleRole, + email: actuary.email, + actuarialFirm: actuary.actuarialFirm, + actuarialFirmOther: actuary.actuarialFirmOther ?? undefined, + })) + : [], + addtlActuaryContacts: rateRevision.addtlActuaryContacts + ? rateRevision.addtlActuaryContacts.map((actuary) => ({ + name: actuary.name, + titleRole: actuary.titleRole, + email: actuary.email, + actuarialFirm: actuary.actuarialFirm, + actuarialFirmOther: actuary.actuarialFirmOther ?? undefined, + })) + : [], + actuaryCommunicationPreference: + rateRevision.actuaryCommunicationPreference ?? undefined, + packagesWithSharedRateCerts: [], // intentionally not handling packagesWithSharedRates yet - this is MR-3568 + } +} + function draftRatesToDomainModel( draftRates: DraftRateWithRelations[] -): RateRevision[] { - return draftRates.map((dr) => ({ - id: dr.revisions[0].id, - revisionFormData: dr.revisions[0].name, - })) +): RateRevisionType[] { + return draftRates.map((dr) => rateReivisionToDomainModel(dr.revisions[0])) +} + +function rateReivisionToDomainModel( + revision: RateRevisionTableWithFormData +): RateRevisionType { + return { + id: revision.id, + createdAt: revision.createdAt, + updatedAt: revision.updatedAt, + revisionFormData: rateFormDataToDomainModel(revision), + } } function ratesRevisionsToDomainModel( - rateRevisions: RateRevisionTable[] -): RateRevision[] { - return rateRevisions.map((rrev) => ({ - id: rrev.id, - revisionFormData: rrev.name, - })) + rateRevisions: RateRevisionTableWithFormData[] +): RateRevisionType[] { + return rateRevisions.map((rrev) => rateReivisionToDomainModel(rrev)) } function draftContractRevToDomainModel( revision: DraftContractRevisionTableWithRelations -): ContractRevisionType { +): ContractRevisionWithRatesType { return { id: revision.id, createdAt: revision.createdAt, @@ -174,9 +235,10 @@ function draftContractToDomainModel( export { contractFormDataToDomainModel, convertUpdateInfoToDomainModel, + ratesRevisionsToDomainModel, + rateFormDataToDomainModel, draftContractRevToDomainModel, draftContractToDomainModel, draftRatesToDomainModel, - ratesRevisionsToDomainModel, getContractStatus, } diff --git a/services/app-api/src/postgres/contractAndRates/submitContract.test.ts b/services/app-api/src/postgres/contractAndRates/submitContract.test.ts index a6ed1034cd..5bdeed0bd3 100644 --- a/services/app-api/src/postgres/contractAndRates/submitContract.test.ts +++ b/services/app-api/src/postgres/contractAndRates/submitContract.test.ts @@ -105,7 +105,7 @@ describe('submitContract', () => { const rateA = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'first rate', + rateCertificationName: 'first rate', }) ) @@ -210,7 +210,7 @@ describe('submitContract', () => { const rate1 = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'onepoint0', + rateCertificationName: 'onepoint0', }) ) must( diff --git a/services/app-api/src/postgres/contractAndRates/submitRate.ts b/services/app-api/src/postgres/contractAndRates/submitRate.ts index 157ec84848..7b1775d550 100644 --- a/services/app-api/src/postgres/contractAndRates/submitRate.ts +++ b/services/app-api/src/postgres/contractAndRates/submitRate.ts @@ -1,6 +1,6 @@ import { PrismaClient } from '@prisma/client' +import { RateType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' import { findRateWithHistory } from './findRateWithHistory' -import { Rate } from '../../domain-models/contractAndRates/rateType' // Update the given revision // * invalidate relationships of previous revision @@ -10,7 +10,7 @@ async function submitRate( rateID: string, submittedByUserID: string, submitReason: string -): Promise { +): Promise { const groupTime = new Date() try { diff --git a/services/app-api/src/postgres/contractAndRates/unlockContract.test.ts b/services/app-api/src/postgres/contractAndRates/unlockContract.test.ts index b539a3faf9..cd14b93671 100644 --- a/services/app-api/src/postgres/contractAndRates/unlockContract.test.ts +++ b/services/app-api/src/postgres/contractAndRates/unlockContract.test.ts @@ -47,7 +47,10 @@ describe('unlockContract', () => { await insertDraftContract(client, draftContractData) ) const rate = must( - await insertDraftRate(client, { stateCode: 'MN', name: 'Rate 1.0' }) + await insertDraftRate(client, { + stateCode: 'MN', + rateCertificationName: 'Rate 1.0', + }) ) // Submit Rate A @@ -138,7 +141,10 @@ describe('unlockContract', () => { await insertDraftContract(client, draftContractData) ) const rate = must( - await insertDraftRate(client, { stateCode: 'MN', name: 'Rate 1.0' }) + await insertDraftRate(client, { + stateCode: 'MN', + rateCertificationName: 'Rate 1.0', + }) ) // Submit Rate A @@ -233,7 +239,10 @@ describe('unlockContract', () => { await insertDraftContract(client, draftContractData) ) const rate = must( - await insertDraftRate(client, { stateCode: 'MN', name: 'rate 1.0' }) + await insertDraftRate(client, { + stateCode: 'MN', + rateCertificationName: 'rate 1.0', + }) ) // Connect draft contract to submitted rate @@ -335,7 +344,10 @@ describe('unlockContract', () => { await insertDraftContract(client, draftContractData) ) const rate = must( - await insertDraftRate(client, { stateCode: 'MN', name: 'rate 1.0' }) + await insertDraftRate(client, { + stateCode: 'MN', + rateCertificationName: 'rate 1.0', + }) ) // Connect draft contract to submitted rate @@ -388,7 +400,7 @@ describe('unlockContract', () => { const rateA = must( await insertDraftRate(client, { stateCode: 'MN', - name: 'rate A 1.1', + rateCertificationName: 'rate A 1.1', }) ) diff --git a/services/app-api/src/postgres/contractAndRates/unlockRate.ts b/services/app-api/src/postgres/contractAndRates/unlockRate.ts index 78fbf075c5..7e224dcf67 100644 --- a/services/app-api/src/postgres/contractAndRates/unlockRate.ts +++ b/services/app-api/src/postgres/contractAndRates/unlockRate.ts @@ -1,6 +1,6 @@ import { PrismaClient } from '@prisma/client' +import { RateType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' import { findRateWithHistory } from './findRateWithHistory' -import { Rate } from '../../domain-models/contractAndRates/rateType' // Unlock the given rate // * copy form data @@ -10,7 +10,7 @@ async function unlockRate( rateID: string, unlockedByUserID: string, unlockReason: string -): Promise { +): Promise { const groupTime = new Date() try { @@ -65,7 +65,7 @@ async function unlockRate( id: rateID, }, }, - name: currentRev.name, + rateCertificationName: currentRev.rateCertificationName, unlockInfo: { create: { updatedAt: groupTime, diff --git a/services/app-api/src/postgres/contractAndRates/updateDraftRate.ts b/services/app-api/src/postgres/contractAndRates/updateDraftRate.ts index 606795fbc3..58afe033cf 100644 --- a/services/app-api/src/postgres/contractAndRates/updateDraftRate.ts +++ b/services/app-api/src/postgres/contractAndRates/updateDraftRate.ts @@ -1,6 +1,6 @@ import { PrismaClient } from '@prisma/client' +import { RateType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema' import { findRateWithHistory } from './findRateWithHistory' -import { Rate } from '../../domain-models/contractAndRates/rateType' // Update the given draft // * can change the set of draftRates @@ -10,7 +10,7 @@ async function updateDraftRate( rateID: string, formData: string, contractIDs: string[] -): Promise { +): Promise { try { // Given all the Rates associated with this draft, find the most recent submitted // rateRevision to update. @@ -30,7 +30,7 @@ async function updateDraftRate( id: currentRev.id, }, data: { - name: formData, + rateCertificationName: formData, draftContracts: { set: contractIDs.map((rID) => ({ id: rID, diff --git a/services/app-api/src/postgres/postgresStore.ts b/services/app-api/src/postgres/postgresStore.ts index 34c3a0af6b..52653e01c0 100644 --- a/services/app-api/src/postgres/postgresStore.ts +++ b/services/app-api/src/postgres/postgresStore.ts @@ -44,7 +44,7 @@ import { } from './questionResponse' import { findAllSupportedStates } from './state' import { - ContractRevisionType, + ContractRevisionWithRatesType, ContractType, } from '../domain-models/contractAndRates/contractAndRatesZodSchema' import { @@ -140,7 +140,7 @@ type Store = { findDraftContract: ( contractID: string - ) => Promise + ) => Promise } function NewPostgresStore(client: PrismaClient): Store { diff --git a/services/app-api/src/postgres/prismaHelpers.ts b/services/app-api/src/postgres/prismaHelpers.ts index a08fbc8b49..4585205ebb 100644 --- a/services/app-api/src/postgres/prismaHelpers.ts +++ b/services/app-api/src/postgres/prismaHelpers.ts @@ -12,8 +12,13 @@ const draftContractRevisionsWithDraftRates = { include: { revisions: { include: { + rateDocuments: true, + supportingDocuments: true, + certifyingActuaryContacts: true, + addtlActuaryContacts: true, submitInfo: updateInfoIncludeUpdater, unlockInfo: updateInfoIncludeUpdater, + draftContracts: true, }, where: { submitInfoID: { not: null }, diff --git a/services/app-api/src/postgres/prismaTypes.ts b/services/app-api/src/postgres/prismaTypes.ts index 43d26599f4..feb86aff17 100644 --- a/services/app-api/src/postgres/prismaTypes.ts +++ b/services/app-api/src/postgres/prismaTypes.ts @@ -12,6 +12,9 @@ import { UpdateInfoTable, User, ContractTable, + RateDocument, + RateSupportingDocument, + ActuaryContact, } from '@prisma/client' // This is the type returned by client.$transaction @@ -27,11 +30,30 @@ type RateRevisionWithRelations = RateRevisionsOnContractRevisionsTable & { } } +type RateOnContractHistory = RateRevisionsOnContractRevisionsTable & { + rateRevision: RateRevisionTable & { + submitInfo?: UpdateInfoTableWithUpdater | null + unlockInfo?: UpdateInfoTableWithUpdater | null + rateDocuments: RateDocument[] + supportingDocuments: RateSupportingDocument[] + certifyingActuaryContacts: ActuaryContact[] + addtlActuaryContacts: ActuaryContact[] + } +} + +type RateRevisionTableWithFormData = RateRevisionTable & { + submitInfo?: UpdateInfoTableWithUpdater | null + unlockInfo?: UpdateInfoTableWithUpdater | null + rateDocuments: RateDocument[] + supportingDocuments: RateSupportingDocument[] + certifyingActuaryContacts: ActuaryContact[] + addtlActuaryContacts: ActuaryContact[] +} type DraftRateWithRelations = RateTable & { - revisions: RateRevisionTable[] + revisions: RateRevisionTableWithFormData[] } -type ContractRevisionTableWithRelations = ContractRevisionTable & { +type ContractRevisionTableWithFormData = ContractRevisionTable & { submitInfo?: UpdateInfoTableWithUpdater | null unlockInfo?: UpdateInfoTableWithUpdater | null stateContacts: StateContact[] @@ -39,7 +61,10 @@ type ContractRevisionTableWithRelations = ContractRevisionTable & { supportingDocuments: ContractSupportingDocument[] managedCareEntities: ManagedCareEntity[] federalAuthorities: FederalAuthority[] - rateRevisions: RateRevisionWithRelations[] +} + +type ContractRevisionTableWithRates = ContractRevisionTableWithFormData & { + rateRevisions: RateOnContractHistory[] } type DraftContractRevisionTableWithRelations = ContractRevisionTable & { @@ -58,12 +83,11 @@ type DraftContractTableWithRelations = ContractTable & { } type ContractTableWithRelations = ContractTable & { - revisions: ContractRevisionTableWithRelations[] + revisions: ContractRevisionTableWithRates[] } type ContractRevisionFormDataType = Omit< - | ContractRevisionTableWithRelations - | DraftContractRevisionTableWithRelations, + ContractRevisionTableWithRates | DraftContractRevisionTableWithRelations, 'rateRevisions' | 'draftRates' > @@ -72,11 +96,13 @@ type UpdateInfoTableWithUpdater = UpdateInfoTable & { updatedBy: User } export type { PrismaTransactionType, UpdateInfoTableWithUpdater, - ContractRevisionTableWithRelations, + ContractRevisionTableWithRates, + ContractRevisionTableWithFormData, DraftContractRevisionTableWithRelations, DraftContractTableWithRelations, RateRevisionWithRelations, DraftRateWithRelations, + RateRevisionTableWithFormData, ContractRevisionFormDataType, ContractTableWithRelations, } diff --git a/services/app-api/src/testHelpers/contractAndRates/contractHelpers.ts b/services/app-api/src/testHelpers/contractAndRates/contractHelpers.ts index 7a24099891..a5d0a0118e 100644 --- a/services/app-api/src/testHelpers/contractAndRates/contractHelpers.ts +++ b/services/app-api/src/testHelpers/contractAndRates/contractHelpers.ts @@ -3,7 +3,7 @@ import { State } from '@prisma/client' import { must } from '../errorHelpers' import { PrismaClient } from '@prisma/client' import { - ContractRevisionTableWithRelations, + ContractRevisionTableWithRates, ContractTableWithRelations, DraftContractRevisionTableWithRelations, DraftContractTableWithRelations, @@ -72,18 +72,17 @@ const createContractData = ( revisions: contract?.revisions ?? [ createContractRevision({ draftRates: undefined, - }) as ContractRevisionTableWithRelations, + }) as ContractRevisionTableWithRates, ], ...contract, }) const createContractRevision = ( revision?: Partial< - | ContractRevisionTableWithRelations - | DraftContractRevisionTableWithRelations + ContractRevisionTableWithRates | DraftContractRevisionTableWithRelations > ): - | ContractRevisionTableWithRelations + | ContractRevisionTableWithRates | DraftContractRevisionTableWithRelations => ({ id: uuidv4(), createdAt: new Date(),