From 8b5a9c1fa56ea90f1b53dd3f268bc76ee2cd1658 Mon Sep 17 00:00:00 2001 From: Mojo Talantikite Date: Thu, 14 Sep 2023 18:21:39 -0400 Subject: [PATCH] just use the client we already get --- services/app-api/src/handlers/proto_to_db.ts | 14 ++++++++------ .../proto_to_db_ContractRevisions.ts | 4 ++-- .../contractAndRates/proto_to_db_Documents.ts | 8 ++++---- .../contractAndRates/proto_to_db_JoinTable.ts | 3 +-- .../proto_to_db_UpdateInfoTable.ts | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/services/app-api/src/handlers/proto_to_db.ts b/services/app-api/src/handlers/proto_to_db.ts index 23271b7681..9044c7901b 100644 --- a/services/app-api/src/handlers/proto_to_db.ts +++ b/services/app-api/src/handlers/proto_to_db.ts @@ -26,7 +26,7 @@ import type { RateTable, } from '@prisma/client' import type { ContractType } from '../domain-models/contractAndRates' -import { PrismaClient } from '@prisma/client' +import type { PrismaClient } from '@prisma/client' import type { ContractTable, ContractRevisionTable } from '@prisma/client' import type { StoreError } from '../postgres/storeError' import { NotFoundError, isStoreError } from '../postgres/storeError' @@ -40,7 +40,10 @@ import { toDomain } from '../../../app-web/src/common-code/proto/healthPlanFormD import type { HealthPlanFormDataType } from '../../../app-web/src/common-code/healthPlanFormDataType' import { findContractWithHistory } from '../postgres/contractAndRates' -export const getDatabaseConnection = async (): Promise => { +export const getDatabaseConnection = async (): Promise<{ + store: Store + prismaClient: PrismaClient +}> => { const dbURL = process.env.DATABASE_URL const secretsManagerSecret = process.env.SECRETS_MANAGER_SECRET @@ -68,7 +71,7 @@ export const getDatabaseConnection = async (): Promise => { } const store = NewPostgresStore(pgResult) - return store + return { store, prismaClient: pgResult } } export const getRevisions = async ( @@ -266,15 +269,14 @@ export const main: Handler = async (): Promise => { } // setup db connections and get revisions - const store = await getDatabaseConnection() - const client = new PrismaClient() + const { store, prismaClient } = await getDatabaseConnection() const revisions = await getRevisions(store) // go through the list of revisons and migrate console.info(`Found ${revisions.length} revisions to migrate...`) const revisionsWithErrors = [] for (const revision of revisions) { - const migrateResult = await migrateRevision(client, revision) + const migrateResult = await migrateRevision(prismaClient, revision) if (migrateResult instanceof Error) { recordException(migrateResult, serviceName, 'migrateRevision') revisionsWithErrors.push(revision.id) diff --git a/services/app-api/src/postgres/contractAndRates/proto_to_db_ContractRevisions.ts b/services/app-api/src/postgres/contractAndRates/proto_to_db_ContractRevisions.ts index 238fe2c0cc..6fd1525159 100644 --- a/services/app-api/src/postgres/contractAndRates/proto_to_db_ContractRevisions.ts +++ b/services/app-api/src/postgres/contractAndRates/proto_to_db_ContractRevisions.ts @@ -98,9 +98,9 @@ async function migrateContractRevision( }) return createdContractRevision - } catch (error) { + } catch (err) { return new Error( - `Error creating contract revision for ID ${revision.id}: ${error.message}` + `Error creating contract revision for ID ${revision.id}: ${err.message}` ) } } diff --git a/services/app-api/src/postgres/contractAndRates/proto_to_db_Documents.ts b/services/app-api/src/postgres/contractAndRates/proto_to_db_Documents.ts index 17a1a6695b..bbc64c27da 100644 --- a/services/app-api/src/postgres/contractAndRates/proto_to_db_Documents.ts +++ b/services/app-api/src/postgres/contractAndRates/proto_to_db_Documents.ts @@ -173,11 +173,11 @@ async function migrateDocuments( } return results - } catch (error) { - const err = new Error( - `Error migrating documents: ${JSON.stringify(error)}` + } catch (err) { + const error = new Error( + `Error migrating documents: ${JSON.stringify(err)}` ) - return err + return error } } diff --git a/services/app-api/src/postgres/contractAndRates/proto_to_db_JoinTable.ts b/services/app-api/src/postgres/contractAndRates/proto_to_db_JoinTable.ts index f002fba0e6..1e16af0926 100644 --- a/services/app-api/src/postgres/contractAndRates/proto_to_db_JoinTable.ts +++ b/services/app-api/src/postgres/contractAndRates/proto_to_db_JoinTable.ts @@ -46,8 +46,7 @@ async function migrateAssociations( } } } - } catch (error) { - console.error(`Error migrating associations: ${JSON.stringify(error)}`) + } catch (err) { return new Error('Error migrating associations') } } diff --git a/services/app-api/src/postgres/contractAndRates/proto_to_db_UpdateInfoTable.ts b/services/app-api/src/postgres/contractAndRates/proto_to_db_UpdateInfoTable.ts index 207ce582aa..aadf7f63ca 100644 --- a/services/app-api/src/postgres/contractAndRates/proto_to_db_UpdateInfoTable.ts +++ b/services/app-api/src/postgres/contractAndRates/proto_to_db_UpdateInfoTable.ts @@ -8,7 +8,7 @@ async function prepopulateUpdateInfo( ): Promise { try { const user = await client.user.findFirst({ - where: { email: { equals: revision.submittedBy ?? '' } }, + where: { email: { equals: revision.submittedBy ?? undefined } }, }) if (!user) {