Skip to content

Commit

Permalink
Requested changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLin0991 committed Jul 14, 2023
1 parent 69e4d9b commit 38e21a1
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ const draftContractZodSchema = contractZodSchema.extend({
revisions: z.array(contractRevisionZodSchema).min(1),
})

type ContractFormData = z.infer<typeof contractFormDataSchema>
type Contract = z.infer<typeof contractZodSchema>
type ContractRevision = z.infer<typeof contractRevisionZodSchema>
type UpdateInfo = z.infer<typeof updateInfoSchema>
type ContractStatus = z.infer<typeof contractZodSchema.shape.status>
type ContractFormDataType = z.infer<typeof contractFormDataSchema>
type ContractType = z.infer<typeof contractZodSchema>
type ContractRevisionType = z.infer<typeof contractRevisionZodSchema>
type UpdateInfoType = z.infer<typeof updateInfoSchema>
type ContractStatusType = z.infer<typeof contractZodSchema.shape.status>

export { contractRevisionZodSchema, draftContractZodSchema, contractZodSchema }

export type {
ContractFormData,
Contract,
ContractRevision,
UpdateInfo,
ContractStatus,
ContractFormDataType,
ContractType,
ContractRevisionType,
UpdateInfoType,
ContractStatusType,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
DraftContractTableWithRelations,
} from '../../postgres/prismaTypes'
import {
Contract,
ContractRevision,
ContractType,
ContractRevisionType,
contractRevisionZodSchema,
draftContractZodSchema,
contractZodSchema,
Expand All @@ -18,7 +18,7 @@ import {

function parseDraftContractRevision(
revision: DraftContractRevisionTableWithRelations
): ContractRevision | Error {
): ContractRevisionType | Error {
const draftContractRevision = draftContractRevToDomainModel(revision)
const parseDraft = contractRevisionZodSchema.safeParse(
draftContractRevision
Expand All @@ -36,7 +36,7 @@ function parseDraftContractRevision(

function parseDraftContract(
contract: DraftContractTableWithRelations
): Contract | Error {
): ContractType | Error {
const draftContract = draftContractToDomainModel(contract)

const parseDraft = draftContractZodSchema.safeParse(draftContract)
Expand All @@ -58,7 +58,7 @@ function parseDraftContract(
function parseContractWithHistory(
contract: ContractTableWithRelations
//contractRevisions: ContractRevisionTableWithRelations[]
): Contract | Error {
): ContractType | Error {
const contractWithHistory = contractWithHistoryToDomainModel(contract)

if (contractWithHistory instanceof Error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrismaTransactionType } from '../prismaTypes'
import { Contract } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { ContractType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { parseContractWithHistory } from '../../domain-models/contractAndRates/parseDomainData'
import { updateInfoIncludeUpdater } from '../prismaHelpers'

Expand All @@ -10,7 +10,7 @@ import { updateInfoIncludeUpdater } from '../prismaHelpers'
async function findContractWithHistory(
client: PrismaTransactionType,
contractID: string
): Promise<Contract | Error> {
): Promise<ContractType | Error> {
try {
const contract = await client.contractTable.findFirst({
where: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PrismaClient } from '@prisma/client'
import { ContractRevision } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { ContractRevisionType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { parseDraftContractRevision } from '../../domain-models/contractAndRates/parseDomainData'
import { draftContractRevisionsWithDraftRates } from '../prismaHelpers'

// findDraftContract returns a draft (if any) for the given contract.
async function findDraftContract(
client: PrismaClient,
contractID: string
): Promise<ContractRevision | undefined | Error> {
): Promise<ContractRevisionType | undefined | Error> {
try {
const draftContractRevision =
await client.contractRevisionTable.findFirst({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
PrismaClient,
PopulationCoverageType,
SubmissionType,
ContractType,
ContractType as PrismaContractType,
} from '@prisma/client'
import { Contract } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { ContractType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { parseDraftContract } from '../../domain-models/contractAndRates/parseDomainData'
import { draftContractRevisionsWithDraftRates } from '../prismaHelpers'

Expand All @@ -15,14 +15,14 @@ type InsertContractArgsType = {
riskBasedContract: boolean
submissionType: SubmissionType
submissionDescription: string
contractType: ContractType
contractType: PrismaContractType
}

// creates a new contract, with a new revision
async function insertDraftContract(
client: PrismaClient,
args: InsertContractArgsType
): Promise<Contract | Error> {
): Promise<ContractType | Error> {
try {
return await client.$transaction(async (tx) => {
const { latestStateSubmissionNumber } = await tx.state.update({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
Contract,
ContractRevision,
ContractFormData,
ContractStatus,
ContractType,
ContractRevisionType,
ContractFormDataType,
ContractStatusType,
} from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { RateRevision } from '../../domain-models/contractAndRates/rateType'
import {
Expand Down Expand Up @@ -46,7 +46,7 @@ function getContractStatus(
ContractRevisionTableWithRelations,
'createdAt' | 'submitInfo'
>[]
): ContractStatus {
): ContractStatusType {
// need to order revisions from latest to earlies
const latestToEarliestRev = revision.sort(
(revA, revB) => revB.createdAt.getTime() - revA.createdAt.getTime()
Expand All @@ -57,7 +57,7 @@ function getContractStatus(

function contractFormDataToDomainModel(
contractRevision: ContractRevisionFormDataType
): ContractFormData {
): ContractFormDataType {
return {
submissionType: contractRevision.submissionType,
submissionDescription: contractRevision.submissionDescription,
Expand Down Expand Up @@ -155,7 +155,7 @@ function ratesRevisionsToDomainModel(

function draftContractRevToDomainModel(
revision: DraftContractRevisionTableWithRelations
): ContractRevision {
): ContractRevisionType {
return {
id: revision.id,
createdAt: revision.createdAt,
Expand All @@ -167,7 +167,7 @@ function draftContractRevToDomainModel(

function contractRevToDomainModel(
revisions: ContractRevisionSet[]
): ContractRevision[] {
): ContractRevisionType[] {
const contractRevisions = revisions.map((entry) => ({
id: entry.contractRev.id,
submitInfo: convertUpdateInfoToDomainModel(entry.submitInfo),
Expand All @@ -185,7 +185,7 @@ function contractRevToDomainModel(

function draftContractToDomainModel(
contract: DraftContractTableWithRelations
): Contract {
): ContractType {
const revisions = contract.revisions.map((cr) =>
draftContractRevToDomainModel(cr)
)
Expand All @@ -199,9 +199,11 @@ function draftContractToDomainModel(
}
}

// contractWithHistoryToDomainModel constructs a history for this particular contract including changes to all of its
// revisions and all related rate revisions, including added and removed rates
function contractWithHistoryToDomainModel(
contract: ContractTableWithRelations
): Contract | Error {
): ContractType | Error {
// We iterate through each contract revision in order, adding it as a revision in the history
// then iterate through each of its rates, constructing a history of any rates that changed
// between contract revision updates
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrismaClient } from '@prisma/client'
import { Contract } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { ContractType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { findContractWithHistory } from './findContractWithHistory'

// Update the given revision
Expand All @@ -10,7 +10,7 @@ async function submitContract(
contractID: string,
submittedByUserID: string,
submitReason: string
): Promise<Contract | Error> {
): Promise<ContractType | Error> {
const groupTime = new Date()

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrismaClient } from '@prisma/client'
import { Contract } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { ContractType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { findContractWithHistory } from './findContractWithHistory'

// Unlock the given contract
Expand All @@ -10,7 +10,7 @@ async function unlockContract(
contractID: string,
unlockedByUserID: string,
unlockReason: string
): Promise<Contract | Error> {
): Promise<ContractType | Error> {
const groupTime = new Date()

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
ContractType,
ContractType as PrismaContractType,
PopulationCoverageType,
PrismaClient,
SubmissionType,
} from '@prisma/client'
import { Contract } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { ContractType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { findContractWithHistory } from './findContractWithHistory'

type UpdateContractArgsType = {
Expand All @@ -13,7 +13,7 @@ type UpdateContractArgsType = {
riskBasedContract: boolean
submissionType: SubmissionType
submissionDescription: string
contractType: ContractType
contractType: PrismaContractType
}

// Update the given draft
Expand All @@ -24,7 +24,7 @@ async function updateDraftContract(
contractID: string,
formData: UpdateContractArgsType,
rateIDs: string[]
): Promise<Contract | Error> {
): Promise<ContractType | Error> {
try {
// Given all the Rates associated with this draft, find the most recent submitted
// rateRevision to update.
Expand Down

0 comments on commit 38e21a1

Please sign in to comment.