Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding initialization work to display conditions.category and build queries #103

19 changes: 19 additions & 0 deletions query-connector/src/app/api/customize-query/conditions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextResponse } from "next/server";
import { getConditionsData } from "@/app/database-service";

/**
* Handles a GET request to fetch conditions data.
* @returns Response with conditions data in JSON format.
*/
export async function GET() {
try {
const conditionsData = await getConditionsData();
return NextResponse.json(conditionsData, { status: 200 });
} catch (error) {
console.error("Error fetching conditions data:", error);
return NextResponse.json(
{ error: "Failed to fetch conditions data" },
{ status: 500 },
);
}
}
14 changes: 14 additions & 0 deletions query-connector/src/app/database-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,17 @@ export async function insertQuery(input: QueryInput) {
if (errorArray.length === 0) return { success: true };
return { success: false, error: errorArray.join(",") };
}

/**
* Retrieves all records from the conditions table in the database.
* This function queries the database to fetch condition data, including
* condition name, code, and category.
* @returns results.rows A promise that resolves to an array of rows,
* each representing a condition with its associated fields (e.g., id, condition name,
* condition code, category). If no records are found, an empty array is returned.
*/
export async function getConditionsData() {
const query = "SELECT * FROM conditions";
const result = await dbClient.query(query);
return result.rows;
}
Loading