-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
continuing full system updates. reworking validation system to operat…
…e by retrieving full coremeasurement row inserted (to get plot/quadrat/personnel info) instead of using user-provided data. Because some of the validations use plot/quadrat, etc., when those validations fail the user-provided data will not provide info about it.
- Loading branch information
1 parent
7dfbb8b
commit 7288db0
Showing
11 changed files
with
190 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {NextRequest, NextResponse} from "next/server"; | ||
import {CoreMeasurementsResult, getConn, getSchema, runQuery} from "@/components/processors/processormacros"; | ||
import {PoolConnection} from "mysql2/promise"; | ||
import {CoreMeasurementsRDS} from "@/config/sqlmacros"; | ||
import {bitToBoolean} from "@/config/macros"; | ||
|
||
export async function GET(request: NextRequest) { | ||
const schema = getSchema(); | ||
const cmID = parseInt(request.nextUrl.searchParams.get('cmid')!); | ||
let conn: PoolConnection | null = null; | ||
try { | ||
conn = await getConn(); | ||
let query = `SELECT * FROM ${schema}.CoreMeasurements WHERE CoreMeasurementID = ? LIMIT 1`; | ||
const results = await runQuery(conn, query, [cmID]); | ||
let coreMeasurementRows: CoreMeasurementsRDS[] = results.map((row: CoreMeasurementsResult, index: number) => ({ | ||
// ... mapping fields ... | ||
id: index + 1, | ||
coreMeasurementID: row.CoreMeasurementID, | ||
censusID: row.CensusID, | ||
plotID: row.PlotID, | ||
quadratID: row.QuadratID, | ||
treeID: row.TreeID, | ||
stemID: row.StemID, | ||
personnelID: row.PersonnelID, | ||
isValidated: bitToBoolean(row.IsValidated), | ||
measurementDate: row.MeasurementDate, | ||
measuredDBH: row.MeasuredDBH, | ||
measuredHOM: row.MeasuredHOM, | ||
description: row.Description, | ||
userDefinedFields: row.UserDefinedFields, | ||
// ... other fields as needed | ||
})); | ||
|
||
return new NextResponse(JSON.stringify(coreMeasurementRows), {status: 200}); | ||
} catch(error: any) { | ||
throw new Error('SQL query failed: ' + error.message); | ||
} finally { | ||
if (conn) conn.release(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.