summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/mediatorApp/src/services/mediatorService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/odlux/apps/mediatorApp/src/services/mediatorService.ts')
-rw-r--r--sdnr/wt/odlux/apps/mediatorApp/src/services/mediatorService.ts74
1 files changed, 48 insertions, 26 deletions
diff --git a/sdnr/wt/odlux/apps/mediatorApp/src/services/mediatorService.ts b/sdnr/wt/odlux/apps/mediatorApp/src/services/mediatorService.ts
index b257fa92c..aee086689 100644
--- a/sdnr/wt/odlux/apps/mediatorApp/src/services/mediatorService.ts
+++ b/sdnr/wt/odlux/apps/mediatorApp/src/services/mediatorService.ts
@@ -19,9 +19,9 @@ import * as $ from 'jquery';
import { requestRest, formEncode } from '../../../../framework/src/services/restService';
import { MediatorServer, MediatorServerVersionInfo, MediatorConfig, MediatorServerDevice, MediatorConfigResponse } from '../models/mediatorServer';
-import { HitEntry } from '../../../../framework/src/models';
+import { PostResponse, DeleteResponse, Result } from '../../../../framework/src/models';
-export const mediatorServerResourcePath = "mwtn/mediator-server";
+export const mediatorServerResourcePath = "mediator-server";
type MediatorServerResponse<TData> = { code: number, data: TData };
type IndexableMediatorServer = MediatorServer & { [key: string]: any; };
@@ -33,46 +33,68 @@ class MediatorService {
/**
* Inserts data into the mediator servers table.
*/
- public async insertMediatorServer(server: IndexableMediatorServer): Promise<MediatorServer | null> {
- const path = `database/${mediatorServerResourcePath}`;
- const data = Object.keys(server).reduce((acc, cur) => {
- if (cur !== "_id") acc[cur] = server[cur];
- return acc;
- }, {} as IndexableMediatorServer);
- const result = await requestRest<MediatorServer>(path, { method: "POST", body: JSON.stringify(data) });
+ public async insertMediatorServer(server: IndexableMediatorServer): Promise<PostResponse | null> {
+ const path = `/restconf/operations/data-provider:create-mediator-server`;
+
+ const data = {
+ "url": server.url,
+ "name": server.name
+ }
+
+ const result = await requestRest<PostResponse>(path, { method: "POST", body: JSON.stringify({ input: data }) });
return result || null;
}
/**
* Updates data into the mediator servers table.
*/
- public async updateMediatorServer(server: IndexableMediatorServer): Promise<MediatorServer | null> {
- const path = `database/${mediatorServerResourcePath}/${server._id}`;
- const data = Object.keys(server).reduce((acc, cur) => {
- if (cur !== "_id") { acc[cur] = server[cur] } else { acc["id"] = 0 };
- return acc;
- }, {} as IndexableMediatorServer);
- const result = await requestRest<MediatorServer>(path, { method: "PUT", body: JSON.stringify(data) });
+ public async updateMediatorServer(server: IndexableMediatorServer): Promise<PostResponse | null> {
+ const path = `/restconf/operations/data-provider:update-mediator-server`;
+
+ const data = {
+ "id": server.id,
+ "url": server.url,
+ "name": server.name
+ }
+
+ const result = await requestRest<PostResponse>(path, { method: "POST", body: JSON.stringify({ input: data }) });
return result || null;
}
/**
* Deletes data from the mediator servers table.
*/
- public async deleteMediatorServer(server: MediatorServer): Promise<MediatorServer | null> {
- const path = `database/${mediatorServerResourcePath}/${server._id}`;
- const result = await requestRest<MediatorServer>(path, { method: "DELETE" });
+ public async deleteMediatorServer(server: MediatorServer): Promise<DeleteResponse | null> {
+ const path = `/restconf/operations/data-provider:delete-mediator-server`;
+
+ const data = {
+ "id": server.id,
+ }
+
+ const result = await requestRest<DeleteResponse>(path, { method: "POST", body: JSON.stringify({ input: data }) });
return result || null;
}
public async getMediatorServerById(serverId: string): Promise<MediatorServer | null> {
- const path = `database/${mediatorServerResourcePath}/${serverId}`;
- const result = await requestRest<HitEntry<MediatorServer> & { found: boolean }>(path, { method: "GET" });
- return result && result.found && result._source && {
- _id: result._id,
- name: result._source.name,
- url: result._source.url,
- } || null;
+ const path = `/restconf/operations/data-provider:read-mediator-server-list`;
+
+ const data = { "filter": [{ "property": "id", "filtervalue": serverId }] }
+
+
+ const result = await requestRest<Result<MediatorServer>>(path, { method: "POST", body: JSON.stringify({ input: data }) });
+
+ if (result && result.output.data[0]) {
+ const firstResult = result.output.data[0];
+
+ return {
+ id: firstResult.id,
+ name: firstResult.name,
+ url: firstResult.url
+ }
+ }
+ else {
+ return null;
+ }
}
// https://cloud-highstreet-technologies.com/wiki/doku.php?id=att:ms:api