Skip to content

Commit

Permalink
changes js code to ts
Browse files Browse the repository at this point in the history
Signed-off-by: Shivam Dhar <[email protected]>
  • Loading branch information
Shivamdhar committed Aug 5, 2022
1 parent 1e34c06 commit 87294cb
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 52 deletions.
34 changes: 0 additions & 34 deletions src/plugins/region_map/server/plugin.js

This file was deleted.

42 changes: 42 additions & 0 deletions src/plugins/region_map/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
PluginInitializerContext,
CoreSetup,
CoreStart,
Plugin,
Logger,
} from 'opensearch-dashboards/server';

import { OpenSearchService } from './services';
import { registerGeospatialRoutes } from '../server/routes';
import { getUiSettings } from './ui_settings';
import { RegionMapPluginSetup, RegionMapPluginStart } from './types';

export class RegionMapPlugin implements Plugin<RegionMapPluginSetup, RegionMapPluginStart> {
private readonly logger: Logger;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
}

public setup(core: CoreSetup) {
this.logger.debug('RegionMap: Setup');
const opensearchClient = core.opensearch.legacy.createClient('opensearch');
const opensearchService = new OpenSearchService(opensearchClient);
const router = core.http.createRouter();
core.uiSettings.register(getUiSettings());
registerGeospatialRoutes(opensearchService, router);
return {};
}

public start(_core: CoreStart) {
this.logger.debug('RegionMap: Started');
return {};
}

public stop() {}
}
4 changes: 1 addition & 3 deletions src/plugins/region_map/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
* SPDX-License-Identifier: Apache-2.0
*/

import opensearch from './opensearch';

export { opensearch };
export { registerGeospatialRoutes } from './opensearch';
5 changes: 3 additions & 2 deletions src/plugins/region_map/server/routes/opensearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/

import { schema } from '@osd/config-schema';
import { IRouter } from 'opensearch-dashboards/server';
import { OpenSearchService } from '../services';

// eslint-disable-next-line import/no-default-export
export default function (services, router) {
export function registerGeospatialRoutes(services: OpenSearchService, router: IRouter) {
router.post(
{
path: '/api/geospatial/_indices',
Expand Down
8 changes: 0 additions & 8 deletions src/plugins/region_map/server/services/index.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/plugins/region_map/server/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export { OpenSearchService } from './opensearch_service';
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
* SPDX-License-Identifier: Apache-2.0
*/

export default class OpensearchService {
constructor(esDriver) {
import {
ILegacyCustomClusterClient,
IOpenSearchDashboardsResponse,
OpenSearchDashboardsRequest,
OpenSearchDashboardsResponseFactory,
RequestHandlerContext,
} from 'opensearch-dashboards/server';

export class OpenSearchService {
esDriver: ILegacyCustomClusterClient;
constructor(esDriver: ILegacyCustomClusterClient) {
this.esDriver = esDriver;
}

getMappings = async (context, req, res) => {
getMappings = async (
context: RequestHandlerContext,
req: OpenSearchDashboardsRequest,
res: OpenSearchDashboardsResponseFactory
): Promise<IOpenSearchDashboardsResponse<any>> => {
try {
const { index } = req.body;
const { callAsCurrentUser } = this.esDriver.asScoped(req);
Expand All @@ -29,7 +42,11 @@ export default class OpensearchService {
}
};

search = async (context, req, res) => {
search = async (
context: RequestHandlerContext,
req: OpenSearchDashboardsRequest,
res: OpenSearchDashboardsResponseFactory
): Promise<IOpenSearchDashboardsResponse<any>> => {
try {
const { query, index, size } = req.body;
const params = { index, size, body: query };
Expand All @@ -51,7 +68,11 @@ export default class OpensearchService {
}
};

getIndex = async (context, req, res) => {
getIndex = async (
context: RequestHandlerContext,
req: OpenSearchDashboardsRequest,
res: OpenSearchDashboardsResponseFactory
): Promise<IOpenSearchDashboardsResponse<any>> => {
try {
const { index } = req.body;
const { callAsCurrentUser } = this.esDriver.asScoped(req);
Expand Down

0 comments on commit 87294cb

Please sign in to comment.