Feature/4 pilots add (#20)

* changing api url to env variable

* updating env variables

* updating env variables

* updating env variables

* updating env variables

* updating env variables

* updating env variables

* feature/4-pilots---add

* feature/4-pilots---add

* feature/4-pilots---add

* feature/4-pilots---add

* ad pilot

* add pilot

* add pilot

* add pilot

* add pilot

* add pilot

* adding pilots

* add pilot

* add pilot

* add pilots

* add pilot

* add pilot

* adding pilots

* adding pilots

* adding pilots

* adding pilots

* adding pilots

* adding pilots

* adding pilots

* adding pilots

* adding pilots

* adding pilots

* adding pilots

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* Testing menu button

* Testing menu button

* Testing menu button

* Testing menu button

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

* adding pilot

---------

Co-authored-by: Noah Spannbauer <nspannbauer@sensonix.com>
This commit was merged in pull request #20.
This commit is contained in:
2024-09-23 20:52:59 -05:00
committed by GitHub
parent 80b4fb8c1d
commit 071e211525
53 changed files with 4184 additions and 13161 deletions

View File

@@ -1,4 +1,11 @@
import { Controller, Get, Query } from '@nestjs/common';
import {
Controller,
Get,
Headers,
Query,
Res,
StreamableFile
} from '@nestjs/common';
import {
AppConfigService,
MsGraphService,
@@ -6,10 +13,17 @@ import {
} from '@noahspan/noahspan-modules';
import { FeatureFlagValue } from '@azure/app-configuration';
import { Public } from '@noahspan/noahspan-modules';
import { Person } from '@microsoft/microsoft-graph-types';
import { AppService } from './app.service';
import { createReadStream } from 'fs';
import { join } from 'path';
import { arrayBuffer } from 'stream/consumers';
import type { Response } from 'express';
@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
private readonly appConfigService: AppConfigService,
private readonly msGraphService: MsGraphService
) {}
@@ -37,21 +51,58 @@ export class AppController {
}
}
@Public()
@Get('profilePhoto')
async getProfilePhoto(@Query() query: any): Promise<any> {}
@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;
}
}
@Get('userProfile')
async getUserProfile(@Query() query: any) {
async getUserProfile(@Headers() headers: any) {
try {
const username: string = query.username;
const graphToken: string = await this.msGraphService.getMsGraphAuth(
headers.authorization.replace('Bearer ', ''),
['user.read']
);
const client: MsGraphClient =
await this.msGraphService.getMsGraphClient();
const userProfile = await client.api(`users/${username}`).get();
await this.msGraphService.getMsGraphClientDelegated(graphToken);
const userProfile = await client.api(`me`).get();
return userProfile;
} catch (error) {
return error;
}
}
@Get('personSearch')
async searchUsers(
@Headers() headers: any,
@Query('search') search: any
): Promise<Person[]> {
try {
const accessToken: string = headers.authorization.replace('Bearer ', '');
const personSearchResults: Person[] =
await this.appService.getPersonSearchResults(accessToken, search);
console.log(personSearchResults);
return personSearchResults;
} catch (error) {
return error;
}
}
}