Feature/1 add projects and about pages (#2)
* adding api * adding projects page * adding project page * updating terraform * updating terraform * adding github workflows
This commit was merged in pull request #2.
This commit is contained in:
78
api/src/app.controller.ts
Normal file
78
api/src/app.controller.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user