Remove ctx from fetch

This commit is contained in:
Adria Navarro 2023-07-17 14:16:12 +02:00
parent 81c6eab05e
commit e7f1bcab9e
4 changed files with 13 additions and 13 deletions

View File

@ -72,7 +72,7 @@ export async function fetchView(ctx: any) {
export async function fetch(ctx: any) { export async function fetch(ctx: any) {
const tableId = utils.getTableId(ctx) const tableId = utils.getTableId(ctx)
ctx.body = await quotas.addQuery(() => sdk.rows.fetch(tableId, ctx), { ctx.body = await quotas.addQuery(() => sdk.rows.fetch(tableId), {
datasourceId: tableId, datasourceId: tableId,
}) })
} }

View File

@ -29,8 +29,8 @@ export async function exportRows(tableId: string, ctx: Ctx) {
return pickApi(tableId).exportRows(ctx) return pickApi(tableId).exportRows(ctx)
} }
export async function fetch(tableId: string, ctx: Ctx) { export async function fetch(tableId: string) {
return pickApi(tableId).fetch(ctx) return pickApi(tableId).fetch(tableId)
} }
export async function fetchView(tableId: string, ctx: Ctx) { export async function fetchView(tableId: string, ctx: Ctx) {

View File

@ -161,8 +161,7 @@ export async function exportRows(ctx: Ctx) {
return apiFileReturn(content) return apiFileReturn(content)
} }
export async function fetch(ctx: Ctx) { export async function fetch(tableId: string) {
const tableId = ctx.params.tableId
return handleRequest(Operation.READ, tableId, { return handleRequest(Operation.READ, tableId, {
includeSqlRelationships: IncludeRelationship.INCLUDE, includeSqlRelationships: IncludeRelationship.INCLUDE,
}) })
@ -172,6 +171,6 @@ export async function fetchView(ctx: Ctx) {
// there are no views in external datasources, shouldn't ever be called // there are no views in external datasources, shouldn't ever be called
// for now just fetch // for now just fetch
const split = ctx.params.viewName.split("all_") const split = ctx.params.viewName.split("all_")
ctx.params.tableId = split[1] ? split[1] : split[0] const tableId = split[1] ? split[1] : split[0]
return fetch(ctx) return fetch(tableId)
} }

View File

@ -27,12 +27,13 @@ import {
import sdk from "../../../../sdk" import sdk from "../../../../sdk"
export async function search(ctx: Ctx) { export async function search(ctx: Ctx) {
const { tableId } = ctx.params
// Fetch the whole table when running in cypress, as search doesn't work // Fetch the whole table when running in cypress, as search doesn't work
if (!env.COUCH_DB_URL && env.isCypress()) { if (!env.COUCH_DB_URL && env.isCypress()) {
return { rows: await fetch(ctx) } return { rows: await fetch(tableId) }
} }
const { tableId } = ctx.params
const db = context.getAppDB() const db = context.getAppDB()
const { paginate, query, ...params } = ctx.request.body const { paginate, query, ...params } = ctx.request.body
params.version = ctx.version params.version = ctx.version
@ -121,13 +122,13 @@ export async function exportRows(ctx: Ctx) {
} }
} }
export async function fetch(ctx: Ctx) { export async function fetch(tableId: string) {
const db = context.getAppDB() const db = context.getAppDB()
const tableId = ctx.params.tableId
let table = await db.get(tableId) let table = await db.get(tableId)
let rows = await getRawTableData(db, tableId) let rows = await getRawTableData(db, tableId)
return outputProcessing(table, rows) const result = await outputProcessing(table, rows)
return result
} }
async function getRawTableData(db: Database, tableId: string) { async function getRawTableData(db: Database, tableId: string) {
@ -151,7 +152,7 @@ export async function fetchView(ctx: Ctx) {
// if this is a table view being looked for just transfer to that // if this is a table view being looked for just transfer to that
if (viewName.startsWith(DocumentType.TABLE)) { if (viewName.startsWith(DocumentType.TABLE)) {
ctx.params.tableId = viewName ctx.params.tableId = viewName
return fetch(ctx) return fetch(viewName)
} }
const db = context.getAppDB() const db = context.getAppDB()