generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from bcgov/emsedt-199
Basic UI + Emsedt 199
- Loading branch information
Showing
27 changed files
with
934 additions
and
192 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AdminController } from './admin.controller'; | ||
|
||
describe('AdminController', () => { | ||
let controller: AdminController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [AdminController], | ||
}).compile(); | ||
|
||
controller = module.get<AdminController>(AdminController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Controller, Get } from "@nestjs/common"; | ||
import { AdminService } from "./admin.service"; | ||
|
||
@Controller("admin") | ||
export class AdminController { | ||
constructor(private readonly adminService: AdminService) {} | ||
|
||
@Get() | ||
findAll(): Promise<any[]> { | ||
return this.adminService.findAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { AdminController } from "./admin.controller"; | ||
import { AdminService } from "./admin.service"; | ||
import { HttpModule } from "@nestjs/axios"; | ||
|
||
@Module({ | ||
imports: [HttpModule], | ||
controllers: [AdminController], | ||
providers: [AdminService], | ||
}) | ||
export class AdminModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AdminService } from './admin.service'; | ||
|
||
describe('AdminService', () => { | ||
let service: AdminService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [AdminService], | ||
}).compile(); | ||
|
||
service = module.get<AdminService>(AdminService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { HttpService } from "@nestjs/axios"; | ||
import { Injectable } from "@nestjs/common"; | ||
import { firstValueFrom } from "rxjs"; | ||
|
||
@Injectable() | ||
export class AdminService { | ||
constructor(private readonly httpService: HttpService) {} | ||
|
||
/** | ||
* Gets a list of all ??? users | ||
* | ||
* @returns all ??? users | ||
*/ | ||
async findAll(): Promise<any[]> { | ||
const bearerToken = await this.getToken(); | ||
const role = "Enmods Admin"; | ||
const url = `${process.env.users_api_base_url}/integrations/${process.env.integration_id}/${process.env.css_environment}/roles/${role}/users`; | ||
const config = { | ||
headers: { Authorization: "Bearer " + bearerToken }, | ||
}; | ||
try { | ||
console.log("trying user api"); | ||
const response = await firstValueFrom(this.httpService.get(url, config)); | ||
console.log(response); | ||
return response.data.data; | ||
} catch (err) { | ||
console.log(err.response?.data || err.message); | ||
throw err; | ||
} | ||
} | ||
|
||
async getToken() { | ||
const url = process.env.users_api_token_url; | ||
const token = `${process.env.users_api_client_id}:${process.env.users_api_client_secret}`; | ||
const encodedToken = Buffer.from(token).toString("base64"); | ||
const config = { | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
Authorization: "Basic " + encodedToken, | ||
}, | ||
}; | ||
const grantTypeParam = new URLSearchParams(); | ||
grantTypeParam.append("grant_type", "client_credentials"); | ||
try { | ||
const response = await firstValueFrom( | ||
this.httpService.post(url, grantTypeParam.toString(), config) | ||
); | ||
return response.data.access_token; | ||
} catch (error) { | ||
console.log(error.response?.data || error.message); | ||
throw error; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.