import { HttpService, Injectable } from '@nestjs/common'; import { AppLogger } from '../../../../logger'; import { HttpError } from '../../../../exceptions/app-error/http-error'; import { GetProjectPermissionRequestDto } from '../../models/dto'; import {AuthorizationGuardModuleConfig} from '../../authorization.guard.module'; @Injectable() export class ApiService { private readonly TAG: string = `${this.constructor.name}`; constructor(private readonly httpService: HttpService, private readonly config: AuthorizationGuardModuleConfig) { AppLogger.log('Init', this.TAG); } public async getAccountProjectRoleNetworkRequest(accessToken: string): Promise { try { const response: any = await this.httpService.get(this.config.accountProjectRoleUrl, { headers: { Authorization: accessToken }, }).toPromise(); return response.data; } catch (error) { throw new HttpError(error); } } public async getAclForUserProjectResourceNameNetworkRequest(accessToken: string): Promise { try { const response: any = await this.httpService.get(this.config.userProjectResourceAclUrl, { headers: { Authorization: accessToken }, }).toPromise(); return response.data; } catch (error) { throw new HttpError(error); } } public async getProjectPermissionsByRoles(accessToken: string, getProjectPermissionRequestDto: GetProjectPermissionRequestDto): Promise { try { const response: any = await this.httpService.get(this.config.projectPermissionUrl, { data: { ...getProjectPermissionRequestDto }, headers: { Authorization: accessToken }, }).toPromise(); return response.data; } catch (error) { throw new HttpError(error); } } public async getSystemPermissionsByRoles(accessToken: string): Promise { try { const response: any = await this.httpService.get(this.config.systemPermissionUrl, { headers: { Authorization: accessToken }, }).toPromise(); return response.data; } catch (error) { throw new HttpError(error); } } public async getAclByIdsNetworkRequest(accessToken: string): Promise { try { const response: any = await this.httpService.get(this.config.aclByIdUrl, { headers: { Authorization: accessToken }, }).toPromise(); return response.data; } catch (error) { throw new HttpError(error); } } }