-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move start transaction in the if statement for saveMetadataToSqlServer * remove random transaction from conditons api sql server * refactor service for condition to simplify logic * [pre-commit.ci] auto fixes from pre-commit hooks * update jsdocs * Update sqlserver healthcheck since previously it wasn't working --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a9d82ef
commit 9112d57
Showing
7 changed files
with
214 additions
and
260 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
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 |
---|---|---|
@@ -1,65 +1,45 @@ | ||
import { NextResponse } from "next/server"; | ||
import sql from "mssql"; | ||
import { get_pool } from "../services/sqlserver_db"; | ||
import { getDB } from "../services/postgres_db"; | ||
|
||
/** | ||
* Retrieves all unique conditions from the ecr_rr_conditions table in the PostgreSQL database. | ||
* @returns A promise resolving to a NextResponse object. | ||
* @throws An error if the connection to the PostgreSQL database fails. | ||
* @returns Array of conditions | ||
* @throws An error if it fails to fetch data | ||
*/ | ||
export const get_conditions_postgres = async () => { | ||
export const get_conditions_postgres = async (): Promise<string[]> => { | ||
const { database, pgPromise } = getDB(); | ||
const { ParameterizedQuery: PQ } = pgPromise; | ||
|
||
try { | ||
const response = await database.tx(async (t) => { | ||
const getConditions = new PQ({ | ||
text: 'SELECT DISTINCT "condition" FROM ecr_rr_conditions ORDER BY "condition"', | ||
}); | ||
|
||
const conditions = await t.any(getConditions); | ||
|
||
return NextResponse.json( | ||
conditions.map((c: any) => c.condition), | ||
{ status: 200 }, | ||
); | ||
const getConditions = new PQ({ | ||
text: 'SELECT DISTINCT "condition" FROM ecr_rr_conditions ORDER BY "condition"', | ||
}); | ||
const conditions = await database.any<{ condition: string }>(getConditions); | ||
|
||
return response; | ||
return conditions.map((c) => c.condition); | ||
} catch (error: any) { | ||
console.error("Error fetching data:", error); | ||
return NextResponse.json({ message: error.message }, { status: 500 }); | ||
console.error("Error fetching data: ", error); | ||
throw Error("Error fetching data"); | ||
} | ||
}; | ||
|
||
/** | ||
* Retrieves all unique conditions from the ecr_rr_conditions table in the SQL Server database. | ||
* @returns A promise resolving to a NextResponse object. | ||
* @throws An error if the connection to the SQL Server database fails. | ||
* @returns Array of conditions | ||
* @throws An error if it fails to fetch data | ||
*/ | ||
export const get_conditions_sqlserver = async () => { | ||
try { | ||
let pool = await get_pool(); | ||
if (!pool) { | ||
return NextResponse.json( | ||
{ message: "Failed to connect to SQL Server." }, | ||
{ status: 500 }, | ||
); | ||
throw Error("Failed to connnect to pool"); | ||
} | ||
|
||
const transaction = new sql.Transaction(pool); | ||
await transaction.begin(); | ||
const request = new sql.Request(transaction); | ||
|
||
const result = await request.query( | ||
"SELECT DISTINCT erc.[condition] FROM ecr_rr_conditions erc ORDER BY erc.[condition]", | ||
); | ||
const conditions: string[] = result.recordset.map((row) => row.condition); | ||
|
||
return NextResponse.json(conditions, { status: 200 }); | ||
const result = await pool.request().query<{ | ||
condition: string; | ||
}>("SELECT DISTINCT condition FROM ecr_rr_conditions ORDER BY condition"); | ||
return result.recordset.map((row) => row.condition); | ||
} catch (error: any) { | ||
console.error("Error fetching data:", error); | ||
return NextResponse.json({ message: error.message }, { status: 500 }); | ||
console.error("Error fetching data: ", error); | ||
throw Error("Error fetching data"); | ||
} | ||
}; |
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
206 changes: 0 additions & 206 deletions
206
containers/ecr-viewer/src/app/api/tests/conditions.service.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.