Initial Nuxt data explorer setup
This commit is contained in:
26
nuxt4-app/server/api/data/[table]/index.get.ts
Normal file
26
nuxt4-app/server/api/data/[table]/index.get.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { parseQuerySegment } from '../../../services/query-parser'
|
||||
import { fetchTableData } from '../../../services/table-service'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const table = event.context.params?.table
|
||||
|
||||
if (!table) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Tabla no especificada' })
|
||||
}
|
||||
|
||||
const query = getQuery(event)
|
||||
const limitValue = Number.parseInt((query.limit as string) ?? '', 10)
|
||||
const limit = Number.isFinite(limitValue) ? Math.min(Math.max(limitValue, 1), 500) : undefined
|
||||
|
||||
const parsedQuery = parseQuerySegment(query.query as string | undefined)
|
||||
|
||||
return await fetchTableData(table, {
|
||||
parsedQuery,
|
||||
limit,
|
||||
filters: {
|
||||
id: (query.id as string) || undefined,
|
||||
createdFrom: (query.created_from as string) || undefined,
|
||||
createdTo: (query.created_to as string) || undefined
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user