From 8f9003115cc43145d0e345ce9bacc5e5a6983ec2 Mon Sep 17 00:00:00 2001 From: sambokar Date: Mon, 25 Mar 2024 15:37:12 -0400 Subject: [PATCH] adding secret to new env being generated in live site --- .../components/processors/processcensus.tsx | 12 ++++++---- .../processors/processorhelperfunctions.tsx | 24 +++++-------------- .../components/processors/processquadrats.tsx | 2 +- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/frontend/components/processors/processcensus.tsx b/frontend/components/processors/processcensus.tsx index cc840f83..fbf28e3f 100644 --- a/frontend/components/processors/processcensus.tsx +++ b/frontend/components/processors/processcensus.tsx @@ -31,6 +31,7 @@ export async function processCensus(props: Readonly): Pr console.log('extracting species ID by code'); const speciesID = await getColumnValueByColumnName( connection, + schema, 'Species', 'SpeciesID', 'SpeciesCode', @@ -42,6 +43,7 @@ export async function processCensus(props: Readonly): Pr console.log('extracting quadrat ID by quadrat name'); const quadratID = await getColumnValueByColumnName( connection, + schema, 'Quadrats', 'QuadratID', 'QuadratName', @@ -52,20 +54,20 @@ export async function processCensus(props: Readonly): Pr console.log('attempting subspecies ID by speciesID'); let subSpeciesID = null; - if (speciesID) subSpeciesID = await getSubSpeciesID(connection, parseInt(speciesID)); + if (speciesID) subSpeciesID = await getSubSpeciesID(connection, schema, parseInt(speciesID)); if (!subSpeciesID) console.log('no subspeciesID found'); // Insert or update Trees with SpeciesID and SubSpeciesID - const treeID = await processTrees(connection, rowData.tag, speciesID, subSpeciesID ?? null); + const treeID = await processTrees(connection, schema, rowData.tag, speciesID, subSpeciesID ?? null); if (treeID === null) throw new Error(`Tree with tag ${rowData.tag} does not exist.`); console.log(`treeID: ${treeID}`); // Insert or update Stems - const stemID = await processStems(connection, rowData.stemtag, treeID, quadratID, rowData.lx, rowData.ly); + const stemID = await processStems(connection, schema, rowData.stemtag, treeID, quadratID, rowData.lx, rowData.ly); if (stemID === null) throw new Error(`Insertion failure at processStems with data: ${[rowData.stemtag, treeID, quadratID, rowData.lx, rowData.ly]}`) console.log(`stemID: ${stemID}`); - const personnelID = await getPersonnelIDByName(connection, fullName); + const personnelID = await getPersonnelIDByName(connection, schema, fullName); if (personnelID === null) throw new Error(`PersonnelID for personnel with name ${fullName} does not exist`); console.log(`personnelID: ${personnelID}`); @@ -114,7 +116,7 @@ export async function processCensus(props: Readonly): Pr // Process Attributes and CMAttributes for codes const codesArray = rowData.codes.split(';').filter(code => code.trim()); - await processCode(connection, codesArray, dbhCMID); + await processCode(connection, schema, codesArray, dbhCMID); // Commit transaction await connection.commit(); diff --git a/frontend/components/processors/processorhelperfunctions.tsx b/frontend/components/processors/processorhelperfunctions.tsx index 6b37de90..ff1f5b51 100644 --- a/frontend/components/processors/processorhelperfunctions.tsx +++ b/frontend/components/processors/processorhelperfunctions.tsx @@ -13,14 +13,12 @@ import {SitesRDS} from "@/config/sqlmacros"; export async function getColumnValueByColumnName( connection: PoolConnection, + schema: string, tableName: string, columnNameToExtract: string, columnNameToSearch: string, columnValueToSearch: T ): Promise { - const schema = process.env.AZURE_SQL_SCHEMA; - if (!schema) throw new Error("Environmental variable extraction for schema failed"); - if (!columnNameToExtract || !columnNameToSearch || !columnValueToSearch) throw new Error('accidentally handed undefined value in parameter'); try { @@ -45,11 +43,9 @@ export async function getColumnValueByColumnName( export async function getSubSpeciesID( connection: PoolConnection, + schema: string, speciesID: number ): Promise { - const schema = process.env.AZURE_SQL_SCHEMA; // Adjust to your MySQL schema environment variable - if (!schema) throw new Error("Environmental variable extraction for schema failed"); - if (!speciesID) throw new Error('received undefined species ID in getSubSpeciesID'); try { @@ -77,12 +73,10 @@ export async function getSubSpeciesID( export async function processCode( connection: PoolConnection, + schema: string, codesArray: string[], coreMeasurementIDConnected: number ) { - const schema = process.env.AZURE_SQL_SCHEMA; // Adjust to your MySQL schema environment variable - if (!schema) throw new Error("Environmental variable extraction for schema failed"); - if (!codesArray || !coreMeasurementIDConnected) throw new Error('undefined codes array OR coremeasurementID received in processCode'); try { @@ -118,13 +112,11 @@ export async function processCode( export async function processTrees( connection: PoolConnection, + schema: string, treeTag: any, speciesID: any, subSpeciesID: any ): Promise { - const schema = process.env.AZURE_SQL_SCHEMA; // Adjust to your MySQL schema environment variable - if (!schema) throw new Error("Environmental variable extraction for schema failed"); - if (!treeTag || !speciesID) throw new Error('undefined treetag or speciesid passed to processTrees'); try { @@ -152,15 +144,13 @@ export async function processTrees( export async function processStems( connection: PoolConnection, + schema: string, stemTag: any, treeID: any, quadratID: any, stemQuadX: any, stemQuadY: any ): Promise { - const schema = process.env.AZURE_SQL_SCHEMA; // Adjust to your MySQL schema environment variable - if (!schema) throw new Error("Environmental variable extraction for schema failed"); - if (!stemTag || !treeID || !quadratID || !stemQuadX || !stemQuadY) throw new Error('process stems: 1 or more undefined parameters received'); try { @@ -186,11 +176,9 @@ export async function processStems( export async function getPersonnelIDByName( connection: PoolConnection, + schema: string, fullName: string ): Promise { - const schema = process.env.AZURE_SQL_SCHEMA; // Adjust to your MySQL schema environment variable - if (!schema) throw new Error("Environmental variable extraction for schema failed"); - // Split the full name into first and last names const [firstName, lastName] = fullName.split(" "); if (!firstName || !lastName) { diff --git a/frontend/components/processors/processquadrats.tsx b/frontend/components/processors/processquadrats.tsx index 67fe3e9a..6265c1b2 100644 --- a/frontend/components/processors/processquadrats.tsx +++ b/frontend/components/processors/processquadrats.tsx @@ -19,7 +19,7 @@ export async function processQuadrats(props: Readonly) { try { console.log('processquadrats: beginning transaction'); await connection.beginTransaction(); - const personnelID = await getPersonnelIDByName(connection, fullName); + const personnelID = await getPersonnelIDByName(connection, schema, fullName); if (personnelID === null) throw new Error(`PersonnelID for personnel with name ${fullName} does not exist`); const query = ` INSERT INTO ${schema}.Quadrats (PlotID, CensusID, PersonnelID, QuadratName, DimensionX, DimensionY, Area, QuadratShape)