Updating api auth and ms graph endpoint (#19)
* Updating api auth and ms graph endpoint * updating feature flag value * Updating get feature flags functions * Updating get feature flags functions
This commit was merged in pull request #19.
This commit is contained in:
@@ -1,34 +1,57 @@
|
||||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
import { AppConfigService, AuthService } from '@noahspan/noahspan-modules';
|
||||
import {
|
||||
AppConfigService,
|
||||
MsGraphService,
|
||||
MsGraphClient
|
||||
} from '@noahspan/noahspan-modules';
|
||||
import { FeatureFlagValue } from '@azure/app-configuration';
|
||||
import { Public } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(
|
||||
private readonly appConfigService: AppConfigService,
|
||||
private readonly authService: AuthService
|
||||
private readonly msGraphService: MsGraphService
|
||||
) {}
|
||||
|
||||
@Public()
|
||||
@Get('featureFlags')
|
||||
async getFeatureFlags(@Query() query: any): Promise<FeatureFlagValue[]> {
|
||||
async getFeatureFlags(
|
||||
@Query() query: any
|
||||
): Promise<{ key: string; enabled: boolean }[]> {
|
||||
try {
|
||||
const token: string = await this.authService.getToken(
|
||||
'client_credentials',
|
||||
process.env.CLIENT_ID,
|
||||
process.env.CLIENT_SECRET,
|
||||
'https://azconfig.io'
|
||||
);
|
||||
const featureFlags: FeatureFlagValue[] =
|
||||
const featureFlagKeys: string[] =
|
||||
query.keys && query.keys.toString().includes(';')
|
||||
? query.keys.split(';')
|
||||
: [query.keys];
|
||||
const featureFlagLabel: string = query.label;
|
||||
const featureFlags: { key: string; enabled: boolean }[] =
|
||||
await this.appConfigService.getFeatureFlags(
|
||||
token,
|
||||
`${query.key}`,
|
||||
query.label
|
||||
featureFlagKeys,
|
||||
featureFlagLabel
|
||||
);
|
||||
|
||||
return featureFlags;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Get('profilePhoto')
|
||||
async getProfilePhoto(@Query() query: any): Promise<any> {}
|
||||
|
||||
@Get('userProfile')
|
||||
async getUserProfile(@Query() query: any) {
|
||||
try {
|
||||
const username: string = query.username;
|
||||
const client: MsGraphClient =
|
||||
await this.msGraphService.getMsGraphClient();
|
||||
const userProfile = await client.api(`users/${username}`).get();
|
||||
|
||||
return userProfile;
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user