-
Notifications
You must be signed in to change notification settings - Fork 0
implement filter-general function #44
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||||||
|
||||||
| if (!op || !column || values.length == 0) { | |
| if (!op || !column || values.length === 0) { |
| 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( | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||||||||
|
||||||||
| op: string, | |
| op: 'AND' | 'OR', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
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.
| if (values.length == 0) { | |
| if (values.length === 0) { |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
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.
| if (values.length == 0) { | |
| return { data: null, error: "No values provided." }; | |
| } |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
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
AI
Nov 21, 2025
There was a problem hiding this comment.
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.
| if (op == "OR") { | |
| if (op === "OR") { |
There was a problem hiding this comment.
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-generalis too generic. We want to convey more information about what this route does by giving it a more descriptive name.