initial launch
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Headers,
|
||||
Query,
|
||||
StreamableFile,
|
||||
UseGuards
|
||||
} from '@nestjs/common';
|
||||
// import { Client as MsGraphClient } from '@microsoft/microsoft-graph-client';
|
||||
import { MsGraphService } from '@noahspan/noahspan-modules'
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(
|
||||
private readonly msGraphService: MsGraphService
|
||||
) {}
|
||||
|
||||
@Get('userPhoto')
|
||||
async getProfilePhoto(@Headers() headers: any): Promise<StreamableFile> {
|
||||
// try {
|
||||
// const graphToken: string = await this.msGraphService.getMsGraphAuth(
|
||||
// headers.authorization.replace('Bearer ', ''),
|
||||
// ['user.read']
|
||||
// );
|
||||
// const client: MsGraphClient =
|
||||
// await this.msGraphService.getMsGraphClientDelegated(graphToken);
|
||||
// const blob: Blob = await client.api(`me/photos('48x48')/$value`).get();
|
||||
// const arrayBuffer: ArrayBuffer = await blob.arrayBuffer();
|
||||
// const buffer: Buffer = Buffer.from(arrayBuffer);
|
||||
|
||||
// return new StreamableFile(buffer, {
|
||||
// type: 'application/json',
|
||||
// disposition: `attachment; filename="user_photo.png"`
|
||||
// });
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
|
||||
try {
|
||||
const buffer = await this.msGraphService.getProfilePhoto(
|
||||
headers.authorization.replace('Bearer ', ''),
|
||||
['user.read']
|
||||
)
|
||||
|
||||
return new StreamableFile(buffer, {
|
||||
type: 'application/json',
|
||||
disposition: `attachment; filename="user_photo.png"`
|
||||
});
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
@Get('userProfile')
|
||||
async getUserProfile(@Headers() headers: any): Promise<any> {
|
||||
// try {
|
||||
// const graphToken: string = await this.msGraphService.getMsGraphAuth(
|
||||
// headers.authorization.replace('Bearer ', ''),
|
||||
// ['user.read']
|
||||
// );
|
||||
// const client: MsGraphClient =
|
||||
// await this.msGraphService.getMsGraphClientDelegated(graphToken);
|
||||
// const userProfile = await client.api(`me`).get();
|
||||
|
||||
// return userProfile;
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
|
||||
try {
|
||||
const userProfile = await this.msGraphService.getUserProfile(headers.authorization.replace('Bearer ', ''));
|
||||
|
||||
return userProfile;
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,9 @@ import { Module } from '@nestjs/common';
|
||||
import { APP_FILTER, APP_GUARD } from '@nestjs/core';
|
||||
import { HttpExceptionFilter } from './filters/http-exception.filter';
|
||||
import { ProjectModule } from './project/project.module';
|
||||
import { AuthGuard, AuthModule, MsGraphModule } from '@noahspan/noahspan-modules'
|
||||
import { AuthGuard, AuthModule, UserModule } from '@noahspan/noahspan-modules'
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import configuration from './config/configuration';
|
||||
import { AppController } from './app.controller';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -23,7 +22,7 @@ import { AppController } from './app.controller';
|
||||
ConfigModule.forRoot({
|
||||
load: [configuration]
|
||||
}),
|
||||
MsGraphModule.registerAsync({
|
||||
UserModule.registerAsync({
|
||||
inject: [ConfigService],
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
@@ -36,7 +35,6 @@ import { AppController } from './app.controller';
|
||||
}),
|
||||
ProjectModule
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
{
|
||||
provide: APP_FILTER,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export default () => ({
|
||||
azureStorageConnectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
|
||||
clientId: process.env.CLIENT_ID,
|
||||
clientSecret: process.env.CLIENT_SECRET,
|
||||
tenantId: process.env.TENANT_ID
|
||||
|
||||
Reference in New Issue
Block a user