Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x | export {}
import { BigQueryAdapter } from '../../adapters/gcp/bigquery'
import { FirestoreAdapter } from '../../adapters/gcp/firestore'
import { CustomError } from '../error'
import { Utils } from '../BaseUtils'
import getEntityDefinition from './getEntityDefinition'
import defineQueryBigQuery from './defineQueryBigQuery'
import performQueryBigQuery from './performQueryBigQuery'
import normalizeResults from './normalizeResults'
import getSchemaBigQuery from './getSchemaBigQuery'
const $bq = new BigQueryAdapter()
const $firestore = new FirestoreAdapter({ databaseId: 'settings' })
export class ApiUtils extends Utils {
constructor() {
super()
}
getEntityDefinition = async (req: any): Promise<Record<string, any>> => {
try {
return await getEntityDefinition(req, $firestore)
} catch (error: any) {
throw new CustomError(
error.message ?? 'Unable to get entity definition',
error.statusCode || 400
)
}
}
generateResponse = async (req: any): Promise<Record<string, any>> => {
try {
req.entityDef = await getEntityDefinition(req, $firestore)
req.query = defineQueryBigQuery(req)
req.queryResult = await performQueryBigQuery(req, $bq)
const results = normalizeResults(req)
return results
} catch (error: any) {
throw new CustomError(
error.message ?? 'Unable to generate response',
error.statusCode || 400
)
}
}
getSchema = async (req: any): Promise<Record<string, any>> => {
try {
return await getSchemaBigQuery(req, $bq)
} catch (error: any) {
throw new CustomError(
error.message ?? 'Unable to determine schema',
error.statusCode || 400
)
}
}
}
|