diff --git a/src/components/db-api/databaseInfo.controller.ts b/src/components/db-api/databaseInfo.controller.ts index 42b8242..0cd1139 100644 --- a/src/components/db-api/databaseInfo.controller.ts +++ b/src/components/db-api/databaseInfo.controller.ts @@ -20,7 +20,10 @@ export const getAllDatabases = async (req: Request, res: Response) => { export const getAllSchemas = async (req: Request, res: Response) => { try { - const response = await axios.get(`${API_BASE_URL}/schemas`); + const { dbname } = req.params; + const response = await axios.get( + `${API_BASE_URL}/database/${encodeURIComponent(dbname)}/schemas`, + ); res.status(httpStatus.OK).send({ data: response.data }); } catch (error) { console.error('Error fetching schemas:', error); @@ -32,7 +35,10 @@ export const getAllSchemas = async (req: Request, res: Response) => { export const getAllTables = async (req: Request, res: Response) => { try { - const response = await axios.get(`${API_BASE_URL}/tables`); + const { dbname } = req.params; + const response = await axios.get( + `${API_BASE_URL}/database/${encodeURIComponent(dbname)}/tables`, + ); res.status(httpStatus.OK).send({ data: response.data }); } catch (error) { console.error('Error fetching tables:', error); @@ -44,11 +50,13 @@ export const getAllTables = async (req: Request, res: Response) => { export const getTableColumns = async (req: Request, res: Response) => { try { - const { schemaName, tableName } = req.params; + const { dbname, schema, table } = req.params; const response = await axios.get( - `${API_BASE_URL}/tables/${encodeURIComponent( - schemaName, - )}/${encodeURIComponent(tableName)}/columns`, + `${API_BASE_URL}/database/${encodeURIComponent( + dbname, + )}/tables/${encodeURIComponent(schema)}/${encodeURIComponent( + table, + )}/columns`, ); const processedColumns = response.data.map((column) => { @@ -89,7 +97,7 @@ export const getTableColumns = async (req: Request, res: Response) => { export const generateChartData = async (req: Request, res: Response) => { try { - const { schema, table } = req.params; + const { dbname, schema, table } = req.params; const { dimension, measures, differential, filters } = req.body; logger.debug('measures', measures); @@ -107,7 +115,9 @@ export const generateChartData = async (req: Request, res: Response) => { parsedFilters, }); - const url = `${API_BASE_URL}/group-by-operation/${schema}/${table}`; + const url = `${API_BASE_URL}/group-by-operation/${encodeURIComponent( + dbname, + )}/${encodeURIComponent(schema)}/${encodeURIComponent(table)}`; const response = await axios.post(url, payload); const mappedData = chartDataGenerator.formatChartDataResponse( diff --git a/src/components/db-api/databaseInfo.router.ts b/src/components/db-api/databaseInfo.router.ts index f8a53f4..0ddfee7 100644 --- a/src/components/db-api/databaseInfo.router.ts +++ b/src/components/db-api/databaseInfo.router.ts @@ -15,15 +15,15 @@ import { const router: Router = Router(); router.get('/database-info/databases', getAllDatabases); -router.get('/database-info/schemas', getAllSchemas); -router.get('/database-info/tables', getAllTables); +router.get('/database-info/:dbname/schemas', getAllSchemas); +router.get('/database-info/:dbname/tables', getAllTables); router.get( - '/database-info/tables/:schemaName/:tableName/columns', + '/database-info/:dbname/tables/:schema/:table/columns', validate(getTableColumnsValidation), getTableColumns, ); router.post( - '/database-info/generate-chart-data/:schema/:table', + '/database-info/generate-chart-data/:dbname/:schema/:table', validate(generateChartDataValidation), generateChartData, ); diff --git a/src/components/db-api/databaseInfo.validation.ts b/src/components/db-api/databaseInfo.validation.ts index 5759241..53c7225 100644 --- a/src/components/db-api/databaseInfo.validation.ts +++ b/src/components/db-api/databaseInfo.validation.ts @@ -3,8 +3,9 @@ import { ValidSchema } from '../../middleware/joiValidate'; export const getTableColumnsValidation: ValidSchema = { params: Joi.object({ - schemaName: Joi.string().required(), - tableName: Joi.string().required(), + dbname: Joi.string().required(), + schema: Joi.string().required(), + table: Joi.string().required(), }), }; @@ -28,6 +29,7 @@ const filterColumnSchema = Joi.object({ export const generateChartDataValidation: ValidSchema = { params: Joi.object({ + dbname: Joi.string().required(), schema: Joi.string().required(), table: Joi.string().required(), }),