Skip to content

Commit

Permalink
adding secret to new env being generated in live site
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshraze committed Mar 25, 2024
1 parent 23cbe74 commit 8f90031
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
12 changes: 7 additions & 5 deletions frontend/components/processors/processcensus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function processCensus(props: Readonly<SpecialProcessingProps>): Pr
console.log('extracting species ID by code');
const speciesID = await getColumnValueByColumnName(
connection,
schema,
'Species',
'SpeciesID',
'SpeciesCode',
Expand All @@ -42,6 +43,7 @@ export async function processCensus(props: Readonly<SpecialProcessingProps>): Pr
console.log('extracting quadrat ID by quadrat name');
const quadratID = await getColumnValueByColumnName(
connection,
schema,
'Quadrats',
'QuadratID',
'QuadratName',
Expand All @@ -52,20 +54,20 @@ export async function processCensus(props: Readonly<SpecialProcessingProps>): 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}`);

Expand Down Expand Up @@ -114,7 +116,7 @@ export async function processCensus(props: Readonly<SpecialProcessingProps>): 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();
Expand Down
24 changes: 6 additions & 18 deletions frontend/components/processors/processorhelperfunctions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import {SitesRDS} from "@/config/sqlmacros";

export async function getColumnValueByColumnName<T>(
connection: PoolConnection,
schema: string,
tableName: string,
columnNameToExtract: string,
columnNameToSearch: string,
columnValueToSearch: T
): Promise<T | null> {
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 {
Expand All @@ -45,11 +43,9 @@ export async function getColumnValueByColumnName<T>(

export async function getSubSpeciesID(
connection: PoolConnection,
schema: string,
speciesID: number
): Promise<number | null> {
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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -118,13 +112,11 @@ export async function processCode(

export async function processTrees(
connection: PoolConnection,
schema: string,
treeTag: any,
speciesID: any,
subSpeciesID: any
): Promise<number | null> {
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 {
Expand Down Expand Up @@ -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<number | null> {
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 {
Expand All @@ -186,11 +176,9 @@ export async function processStems(

export async function getPersonnelIDByName(
connection: PoolConnection,
schema: string,
fullName: string
): Promise<number | null> {
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) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/processors/processquadrats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function processQuadrats(props: Readonly<SpecialProcessingProps>) {
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)
Expand Down

0 comments on commit 8f90031

Please sign in to comment.