Restruct
parent
ee211030ae
commit
931b6c95af
File diff suppressed because one or more lines are too long
|
|
@ -1,31 +1,19 @@
|
||||||
import { Controller, Get, Post } from '@nestjs/common';
|
import { Controller, Get, Post } from '@nestjs/common';
|
||||||
import { MufapiService, ConnectorsService } from './mufapi.service';
|
import { MufapiService } from './mufapi.service';
|
||||||
|
|
||||||
@Controller('api')
|
@Controller('api')
|
||||||
export class MufapiController {
|
export class MufapiController {
|
||||||
|
|
||||||
constructor(private readonly mufapiService: MufapiService) {}
|
constructor(private readonly mufapiService: MufapiService) {}
|
||||||
//Получаем данные по GET, потом это изничтожим
|
|
||||||
@Get()
|
@Get()
|
||||||
async getHello() : Promise<string> {
|
async getHello() {
|
||||||
let connector : ConnectorsService = new ConnectorsService();
|
let token = this.mufapiService.getAccessToken();
|
||||||
connector.SetConnData();
|
return token;
|
||||||
return await this.mufapiService.getAccessToken(connector.path, connector.creds, connector.options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('test')
|
|
||||||
async getQuery() : Promise<string> {
|
|
||||||
let connector : ConnectorsService = new ConnectorsService();
|
|
||||||
connector.SetConnData();
|
|
||||||
let token : string =await this.mufapiService.getAccessToken(connector.path, connector.creds, connector.options);
|
|
||||||
connector.GetMenuData(token);
|
|
||||||
return await this.mufapiService.getMenu(connector.path, connector.body, connector.options);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Получаем данные по POST будет финалка
|
|
||||||
@Post('menu')
|
@Post('menu')
|
||||||
getMenu () : JSON {
|
getMenu () {
|
||||||
let menu : JSON = JSON.parse('{"id": 2}');
|
let menu = this.mufapiService.getMenu();
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ export class ConnectorsService {
|
||||||
};
|
};
|
||||||
|
|
||||||
//Пробуем получить данные для меню
|
//Пробуем получить данные для меню
|
||||||
GetMenuData (token : string){
|
SetMenuData (token : string){
|
||||||
this.path = 'http://192.168.244.1/e-cmdb/api/query';
|
this.path = 'http://192.168.244.1/e-cmdb/api/query';
|
||||||
this.body = '{"id":["/measures/device$18"],"data":{"links":{"flatten":true,"filter":{"cls":"measure"},"fields":["$id","id","cls","name"]}},"postQuery":"links","enableActions":false,"ts":1740060679399}';
|
this.body = '{"id":["/measures/device$18"],"data":{"links":{"flatten":true,"filter":{"cls":"measure"},"fields":["$id","id","cls","name"]}},"postQuery":"links","enableActions":false,"ts":1740060679399}';
|
||||||
this.options = {
|
this.options = {
|
||||||
|
|
@ -49,13 +49,18 @@ export class MufapiService {
|
||||||
|
|
||||||
token: string; //Глобальная переменная класса под токен
|
token: string; //Глобальная переменная класса под токен
|
||||||
//Получение токена через шаблонизацию
|
//Получение токена через шаблонизацию
|
||||||
async getAccessToken (path:string, body:string, headers) : Promise<string> {
|
async getAccessToken () {
|
||||||
interface Authtorise {
|
interface Authtorise {
|
||||||
access_token: string;
|
access_token: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let connService : ConnectorsService = new ConnectorsService;
|
||||||
|
connService.SetConnData();
|
||||||
|
|
||||||
let auth : Authtorise;
|
let auth : Authtorise;
|
||||||
this.token = 'Error';
|
this.token = 'Error';
|
||||||
await axios.post(path, body, headers).then((response)=>{
|
|
||||||
|
await axios.post(connService.path, connService.creds, connService.options).then((response)=>{
|
||||||
auth = response.data;
|
auth = response.data;
|
||||||
this.token = auth.access_token;
|
this.token = auth.access_token;
|
||||||
}).catch((error)=>{
|
}).catch((error)=>{
|
||||||
|
|
@ -65,14 +70,24 @@ export class MufapiService {
|
||||||
return this.token;
|
return this.token;
|
||||||
}
|
}
|
||||||
//Получение данных для формирования меню в МУФ
|
//Получение данных для формирования меню в МУФ
|
||||||
async getMenu (path:string, body:string, headers) : Promise<string> {
|
async getMenu () {
|
||||||
//*interface MenuController {
|
interface MenuController {
|
||||||
// name: string;
|
id: number,
|
||||||
//
|
name: string,
|
||||||
let resp : string = 'Zlo';
|
}
|
||||||
await axios.post(path, body, headers).then((response)=>{
|
|
||||||
resp = response.data;
|
await this.getAccessToken();
|
||||||
// this.token=resp.name;
|
|
||||||
|
let connService : ConnectorsService = new ConnectorsService;
|
||||||
|
connService.SetMenuData(this.token);
|
||||||
|
|
||||||
|
//let resp : MenuController;
|
||||||
|
let resp : string = '';
|
||||||
|
console.log(connService.path);
|
||||||
|
console.log(connService.body);
|
||||||
|
await axios.post(connService.path, connService.body, connService.options).then((response)=>{
|
||||||
|
resp = JSON.parse(response.data);
|
||||||
|
//this.token=resp[1].name;
|
||||||
//this.token = auth.access_token;
|
//this.token = auth.access_token;
|
||||||
console.log(resp);
|
console.log(resp);
|
||||||
}).catch((error)=>{
|
}).catch((error)=>{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue