Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/app/api/filter-general/route.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name of the directory filter-general is too generic. We want to convey more information about what this route does by giving it a more descriptive name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to implement the route.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { filter_general } from "@/lib/api/filter_general";

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);

const op = searchParams.get("op");
const column = searchParams.get("column");
const values = searchParams.getAll("values");

if (!op || !column || values.length == 0) {
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strict equality operator (===) instead of loose equality (==) to avoid type coercion issues.

Suggested change
if (!op || !column || values.length == 0) {
if (!op || !column || values.length === 0) {

Copilot uses AI. Check for mistakes.
return Response.json(
{ data: null, error: "Missing op, column, or values." },
{ status: 400 }
);
}

const result = await filter_general(op, column, values);

if (result.error) {
return Response.json(result, { status: 400 });
}

return Response.json(result, { status: 200 });
}
45 changes: 45 additions & 0 deletions src/lib/api/filter_general.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createClient } from "../client/supabase/server";

export async function filter_general(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment to route naming. This function should be given a more descriptive name. The current name doesn't communicate what this method does.

op: string,
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'op' parameter allows any string value but only 'AND' and 'OR' are valid. Consider using a union type (op: 'AND' | 'OR') to enforce valid values at compile time and improve type safety.

Suggested change
op: string,
op: 'AND' | 'OR',

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) Not a big fan of the name op. Something like matchType is more descriptive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rely on the TypeScript type system to enforce the validity of the value of op (as well as for other arguments.)

I suggest you created either an Enum or a literal value type for op.

type MatchType = "any" | "all";

then you can type the function argument as follows:

function filter_general(op: MatchType, ...)

and the ts compiler will let you know if the function contract is being violated when you pass in the wrong values for op.

column: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for OP. This should be a type or an enum.

values: string[]
) {
Comment on lines +3 to +7
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc documentation for this public API function. Should include descriptions of parameters (op, column, values), the return type, and examples of valid operations. See getExample.ts comments for reference style.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of this function should be typed.

const valid_columns = [
"name_org",
"pseudonym",
"pronouns",
"email",
"phone",
"position",
"opt_in_communication",
];
Comment on lines +8 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get rid of this in favor of introducing a type or an enum for valid columns in a centralized helper in this codebase.


if (!valid_columns.includes(column)) {
return { data: null, error: "Invalid column name" };
}

const client = await createClient();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to be after all of the validation checks. This way we don't have to create a client before returning due to values being empty.


if (values.length == 0) {
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strict equality operator (===) instead of loose equality (==) to avoid type coercion issues.

Suggested change
if (values.length == 0) {
if (values.length === 0) {

Copilot uses AI. Check for mistakes.
return { data: null, error: "No values provided." };
}
Comment on lines +24 to +26
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values.length check at line 24 is redundant since the route handler already validates this condition at line 10. This duplicate validation should be removed or the route handler's check should be removed to avoid redundancy.

Suggested change
if (values.length == 0) {
return { data: null, error: "No values provided." };
}

Copilot uses AI. Check for mistakes.

if (op == "AND") {
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strict equality operator (===) instead of loose equality (==) to avoid type coercion issues.

Copilot uses AI. Check for mistakes.
const uniqueValues = [...new Set(values)];

if (uniqueValues.length > 1) {
return { data: [], error: null }; // Return empty result if there are multiple unique values
}

const value = uniqueValues[0];

const result = await client.from("Volunteers").select().eq(column, value);
return result;
}
if (op == "OR") {
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strict equality operator (===) instead of loose equality (==) to avoid type coercion issues.

Suggested change
if (op == "OR") {
if (op === "OR") {

Copilot uses AI. Check for mistakes.
const result = await client.from("Volunteers").select().in(column, values);
return result;
}
return { data: null, error: "Invalid operation." };
}
Loading