Skip to content

DT-66: Implementation of table data fetching and filtering#67

Merged
abdotop merged 8 commits intomasterfrom
66-implementation-of-table-data-fetching-and-filtering
Oct 21, 2025
Merged

DT-66: Implementation of table data fetching and filtering#67
abdotop merged 8 commits intomasterfrom
66-implementation-of-table-data-fetching-and-filtering

Conversation

@abdotop
Copy link
Member

@abdotop abdotop commented Oct 8, 2025

No description provided.

@abdotop abdotop requested a review from Copilot October 8, 2025 08:18
@abdotop abdotop self-assigned this Oct 8, 2025
@abdotop abdotop added the tournament Pull requests that are related to the Tournament team label Oct 8, 2025
@abdotop abdotop linked an issue Oct 8, 2025 that may be closed by this pull request
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements table data fetching and filtering functionality for database deployments. It adds a new API endpoint to query table data with support for filtering, sorting, pagination, and search capabilities.

  • Adds a new fetchTablesData function with query construction utilities for WHERE and ORDER BY clauses
  • Creates a new POST endpoint /api/deployment/table/data for retrieving filtered table data
  • Implements SQL injection protection through basic string escaping

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
api/sql.ts Adds core table data fetching logic with query construction functions
api/routes.ts Implements new API endpoint with input validation and schema verification

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +164 to +165
const safeValue = value.replace(/'/g, "''")
whereClauses.push(`${key} ${comparator} '${safeValue}'`)
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

This basic string escaping approach is insufficient for SQL injection protection. Consider using parameterized queries or a proper SQL escaping library instead of manual quote replacement.

Copilot uses AI. Check for mistakes.
}
if (params.search) {
const searchClauses = Array.from(columnsMap.values()).map((col) => {
return `${col.name} LIKE '%${params.search.replace(/'/g, "''")}%'`
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

The search functionality uses the same vulnerable string escaping approach. This could allow SQL injection through the search parameter.

Copilot uses AI. Check for mistakes.
api/routes.ts Outdated
'POST/api/deployment/table/data': route({
fn: (_, { deployment, table, ...input }) => {
const depData = DeploymentsCollection.get(deployment)
if (!deployment) {
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

The condition checks !deployment but should check !depData since deployment is the input parameter and depData is the result from the collection lookup.

Suggested change
if (!deployment) {
if (!depData) {

Copilot uses AI. Check for mistakes.
api/sql.ts Outdated
Comment on lines +214 to +217
limitOffsetClause += `LIMIT ${params.limit} `

if (params.offset && parseInt(params.offset) >= 0) {
limitOffsetClause += `OFFSET ${params.offset} `
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

Direct string interpolation of limit and offset values without validation could allow SQL injection. Although parseInt is used for validation, the original string values are interpolated into the query.

Suggested change
limitOffsetClause += `LIMIT ${params.limit} `
if (params.offset && parseInt(params.offset) >= 0) {
limitOffsetClause += `OFFSET ${params.offset} `
const limit = parseInt(params.limit, 10)
limitOffsetClause += `LIMIT ${limit} `
if (params.offset && parseInt(params.offset) >= 0) {
const offset = parseInt(params.offset, 10)
limitOffsetClause += `OFFSET ${offset} `

Copilot uses AI. Check for mistakes.
@abdotop abdotop force-pushed the 66-implementation-of-table-data-fetching-and-filtering branch 7 times, most recently from 99f9f43 to 51805fb Compare October 8, 2025 10:08
@abdotop abdotop requested a review from Copilot October 8, 2025 10:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

api/sql.ts Outdated
Comment on lines +214 to +216
const query =
`SELECT * FROM ${params.table} ${whereClause} ${orderByClause} ${limitOffsetClause}`
.trim()
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

The table name is directly interpolated into the SQL query without validation or escaping. This could allow SQL injection if the table parameter is not properly validated upstream.

Copilot uses AI. Check for mistakes.
Comment on lines +471 to +472
limit: STR('The maximum number of rows to return'),
offset: STR('The number of rows to skip'),
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

The limit and offset parameters should be defined as numbers (NUM) rather than strings (STR) since they represent numeric values and are parsed as integers in the implementation.

Suggested change
limit: STR('The maximum number of rows to return'),
offset: STR('The number of rows to skip'),
limit: NUM('The maximum number of rows to return'),
offset: NUM('The number of rows to skip'),

Copilot uses AI. Check for mistakes.
api/routes.ts Outdated
const columnsMap = new Map(
tableDef.columns.map((col) => [col.name, col]),
)

Copy link
Member

Choose a reason for hiding this comment

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

// could prepare the data once to only do this in the route:
const columnsMap = formattedSchema[deployement]?.[table]

api/sql.ts Outdated
const { key, comparator, value } = filter
const column = columnsMap.get(key)
if (!column) {
throw new Error(`Invalid filter column: ${key}`)
Copy link
Member

Choose a reason for hiding this comment

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

no need for new for basic Error

api/sql.ts Outdated
}
}
if (params.search) {
const searchClauses = Array.from(columnsMap.values()).map((col) => {
Copy link
Member

Choose a reason for hiding this comment

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

instead of Array.from(columnsMap.values()).map(...)
do columnsMap.values().map(...).toArray()

api/sql.ts Outdated
const orderByClause = constructOrderByClause(params, columnsMap)

let limitOffsetClause = ''
const limit = parseInt(params.limit, 10)
Copy link
Member

Choose a reason for hiding this comment

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

use Math.floor(Number(params.limit))

@abdotop abdotop force-pushed the 66-implementation-of-table-data-fetching-and-filtering branch from 51805fb to 3b86820 Compare October 13, 2025 09:42
… of github.com:01-edu/devtools into 66-implementation-of-table-data-fetching-and-filtering
@abdotop abdotop force-pushed the 66-implementation-of-table-data-fetching-and-filtering branch from 3b86820 to 1dc16e2 Compare October 14, 2025 09:34
* feat(routes): change endpoint from GET to POST for deployment table data retrieval

feat(Filtre): export parseFilters and parseSort functions for external use

feat(DeploymentPage): integrate filter and sort functionality for deployment table data

* feat(DeploymentPage): refactor data fetching and improve table display logic

* feat(DeploymentPage): refactor layout and improve component structure

* fix(DeploymentPage): correct parameter name from tq to qt for search functionality
@abdotop abdotop marked this pull request as ready for review October 21, 2025 11:59
@abdotop abdotop merged commit 7759dbc into master Oct 21, 2025
1 check passed
@abdotop abdotop deleted the 66-implementation-of-table-data-fetching-and-filtering branch October 21, 2025 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tournament Pull requests that are related to the Tournament team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementation of Table data fetching and filtering

3 participants