Feature/6 pilots delete (#42)
* adding pilot delete * adding pilot delete * adding pilot delete
This commit was merged in pull request #42.
This commit is contained in:
@@ -19,23 +19,18 @@
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@azure/app-configuration": "^1.8.0",
|
||||
"@azure/data-tables": "^13.2.2",
|
||||
"@azure/msal-node": "^2.16.2",
|
||||
"@microsoft/microsoft-graph-client": "^3.0.7",
|
||||
"@nestjs/axios": "^3.0.3",
|
||||
"@nestjs/azure-database": "^3.0.0",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/config": "^3.2.2",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/passport": "^10.0.3",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@noahspan/azure-database": "^3.1.2",
|
||||
"@noahspan/noahspan-modules": "^0.9.2",
|
||||
"@schematics/angular": "^17.3.7",
|
||||
"dotenv": "^16.4.7",
|
||||
"express-jwt": "^8.5.1",
|
||||
"passport-azure-ad": "^4.3.5",
|
||||
"reflect-metadata": "0.1.13",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"uuid": "^10.0.0"
|
||||
},
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Headers,
|
||||
Query,
|
||||
StreamableFile,
|
||||
UseGuards
|
||||
} from '@nestjs/common';
|
||||
import { Client as MsGraphClient } from '@microsoft/microsoft-graph-client';
|
||||
import { MsGraphService } from './msGraph/ms-graph.service'
|
||||
import { Person } from '@microsoft/microsoft-graph-types';
|
||||
import { AppService } from './app.service';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Controller()
|
||||
@UseGuards(AuthGuard('azure-ad'))
|
||||
export class AppController {
|
||||
constructor(
|
||||
private readonly appService: AppService,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
@Get('personSearch')
|
||||
async searchUsers(
|
||||
@Headers() headers: any,
|
||||
@Query('search') search: any
|
||||
): Promise<any> {
|
||||
try {
|
||||
const accessToken: string = headers.authorization.replace('Bearer ', '');
|
||||
const personSearchResults: any[] =
|
||||
await this.appService.getPersonSearchResults(accessToken, search);
|
||||
|
||||
return personSearchResults;
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
@Get('hello')
|
||||
async getHello(): Promise<string> {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { MsGraphModule } from './msGraph/ms-graph.module';
|
||||
import { FeatureFlagModule } from './featureFlag/feature-flag.module'
|
||||
import { LogModule } from './log/log.module';
|
||||
import { PilotModule } from './pilot/pilot.module';
|
||||
import { APP_FILTER } from '@nestjs/core';
|
||||
import { APP_FILTER, APP_GUARD, Reflector } from '@nestjs/core';
|
||||
import { HttpExceptionFilter } from './filters/http-exception.filter';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { AuthGuard, AuthModule, UserModule } from '@noahspan/noahspan-modules';
|
||||
import configuration from './config/configuration';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
AuthModule.registerAsync({
|
||||
inject: [ConfigService],
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
@@ -22,33 +20,35 @@ import configuration from './config/configuration';
|
||||
tenantId: configService.get<string>('tenantId')
|
||||
};
|
||||
},
|
||||
inject: [ConfigService]
|
||||
}),
|
||||
ConfigModule.forRoot({
|
||||
load: [configuration]
|
||||
}),
|
||||
FeatureFlagModule,
|
||||
LogModule,
|
||||
MsGraphModule.registerAsync({
|
||||
PilotModule,
|
||||
UserModule.registerAsync({
|
||||
inject: [ConfigService],
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
clientId: configService.get<string>('clientId'),
|
||||
clientSecret: configService.get<string>('clientSecret'),
|
||||
tenantId: configService.get<string>('tenantId')
|
||||
};
|
||||
},
|
||||
inject: [ConfigService]
|
||||
}),
|
||||
PilotModule
|
||||
}
|
||||
}
|
||||
})
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
{
|
||||
provide: APP_FILTER,
|
||||
useClass: HttpExceptionFilter
|
||||
},
|
||||
AppService
|
||||
{
|
||||
provide: APP_GUARD,
|
||||
useClass: AuthGuard
|
||||
},
|
||||
Reflector
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
// import { MsGraphService, MsGraphClient } from '@noahspan/noahspan-modules';
|
||||
import { Client as MsGraphClient } from '@microsoft/microsoft-graph-client';
|
||||
import { MsGraphService } from './msGraph/ms-graph.service';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
constructor(private readonly msGraphService: MsGraphService) {}
|
||||
|
||||
getHello(): string {
|
||||
return JSON.stringify(process.env);
|
||||
}
|
||||
|
||||
async getPersonSearchResults(
|
||||
accessToken: string,
|
||||
search: string
|
||||
): Promise<any[]> {
|
||||
try {
|
||||
const graphToken: string = await this.msGraphService.getMsGraphAuth(
|
||||
accessToken,
|
||||
['user.read']
|
||||
);
|
||||
const client: MsGraphClient =
|
||||
await this.msGraphService.getMsGraphClientDelegated(graphToken);
|
||||
const results: any = await client
|
||||
.api('users')
|
||||
.header('ConsistencyLevel', 'eventual')
|
||||
.search(`"displayName:${search}"`)
|
||||
.orderby('displayName')
|
||||
.select(['displayName', 'userPrincipalName'])
|
||||
.get();
|
||||
let personResults: any[];
|
||||
|
||||
if (results.value) {
|
||||
personResults = results.value.filter((result: any) => {
|
||||
if (result.userPrincipalName !== null) {
|
||||
return result;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
personResults = [];
|
||||
}
|
||||
|
||||
return personResults;
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,10 @@ import { LogDto } from './log.dto';
|
||||
import { Log } from './log.entity';
|
||||
import { LogService } from './log.service';
|
||||
import { CustomError } from '../error/customError';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { Public } from '@noahspan/noahspan-modules';
|
||||
|
||||
|
||||
@Controller('logs')
|
||||
@UseGuards(AuthGuard('azure-ad'))
|
||||
export class LogController {
|
||||
constructor(private readonly logService: LogService) {}
|
||||
|
||||
@@ -35,7 +34,7 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
// @Public()
|
||||
@Public()
|
||||
@Get()
|
||||
async findAll(): Promise<Log[]> {
|
||||
try {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
export interface MsGraphModuleOptions {
|
||||
tenantId: string;
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
import { ConfigurableModuleBuilder } from '@nestjs/common';
|
||||
import { MsGraphModuleOptions } from './ms-graph.interface';
|
||||
|
||||
export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder<MsGraphModuleOptions>().build()
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MsGraphService } from './ms-graph.service';
|
||||
import { ConfigurableModuleClass } from './ms-graph.module-definition';
|
||||
|
||||
@Module({
|
||||
providers: [MsGraphService],
|
||||
exports: [MsGraphService]
|
||||
})
|
||||
export class MsGraphModule extends ConfigurableModuleClass {}
|
||||
@@ -1,41 +0,0 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { MsGraphModuleOptions } from './ms-graph.interface';
|
||||
import { Client } from '@microsoft/microsoft-graph-client';
|
||||
import { AuthenticationResult, ConfidentialClientApplication, OnBehalfOfRequest } from '@azure/msal-node';
|
||||
import { MODULE_OPTIONS_TOKEN } from './ms-graph.module-definition';
|
||||
|
||||
@Injectable()
|
||||
export class MsGraphService {
|
||||
constructor(@Inject(MODULE_OPTIONS_TOKEN) private msGraphModuleOptions: MsGraphModuleOptions) {}
|
||||
|
||||
async getMsGraphAuth(accessToken: string, scopes: string[]): Promise<string> {
|
||||
try {
|
||||
const oboRequest: OnBehalfOfRequest = {
|
||||
oboAssertion: accessToken,
|
||||
scopes: scopes
|
||||
}
|
||||
const cca = new ConfidentialClientApplication({
|
||||
auth: {
|
||||
clientId: this.msGraphModuleOptions.clientId,
|
||||
clientSecret: this.msGraphModuleOptions.clientSecret,
|
||||
authority: `https://login.microsoftonline.com/${this.msGraphModuleOptions.tenantId}`
|
||||
}
|
||||
});
|
||||
const authenticationResult: AuthenticationResult = await cca.acquireTokenOnBehalfOf(oboRequest);
|
||||
|
||||
return authenticationResult.accessToken
|
||||
} catch (error) {
|
||||
return error
|
||||
}
|
||||
}
|
||||
|
||||
async getMsGraphClientDelegated(accessToken): Promise<Client> {
|
||||
const client = await Client.init({
|
||||
authProvider: (done) => {
|
||||
done(null, accessToken);
|
||||
}
|
||||
});
|
||||
|
||||
return client;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Repository, InjectRepository } from '@noahspan/azure-database';
|
||||
import { Medical } from './medical.entity';
|
||||
// import { Injectable } from '@nestjs/common';
|
||||
// import { Repository, InjectRepository } from '@noahspan/azure-database';
|
||||
// import { Medical } from './medical.entity';
|
||||
|
||||
@Injectable()
|
||||
export class MedicalService {
|
||||
private readonly partitionKey: string = 'medical';
|
||||
// @Injectable()
|
||||
// export class MedicalService {
|
||||
// private readonly partitionKey: string = 'medical';
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Medical)
|
||||
private readonly profileRepository: Repository<Medical>
|
||||
) {}
|
||||
// constructor(
|
||||
// @InjectRepository(Medical)
|
||||
// private readonly profileRepository: Repository<Medical>
|
||||
// ) {}
|
||||
|
||||
async find(rowKey: string): Promise<Medical> {
|
||||
return this.profileRepository.find(this.partitionKey, rowKey);
|
||||
}
|
||||
// async find(rowKey: string): Promise<Medical> {
|
||||
// return this.profileRepository.find(this.partitionKey, rowKey);
|
||||
// }
|
||||
|
||||
async findAll(): Promise<Medical[]> {
|
||||
return this.profileRepository.findAll();
|
||||
}
|
||||
// async findAll(): Promise<Medical[]> {
|
||||
// return this.profileRepository.findAll();
|
||||
// }
|
||||
|
||||
async create(profile: Medical): Promise<Medical> {
|
||||
return this.profileRepository.create(profile);
|
||||
}
|
||||
// async create(profile: Medical): Promise<Medical> {
|
||||
// return this.profileRepository.create(profile);
|
||||
// }
|
||||
|
||||
async update(rowKey: string, profile: Medical): Promise<Medical> {
|
||||
return this.profileRepository.update(this.partitionKey, rowKey, profile);
|
||||
}
|
||||
// async update(rowKey: string, profile: Medical): Promise<Medical> {
|
||||
// return this.profileRepository.update(this.partitionKey, rowKey, profile);
|
||||
// }
|
||||
|
||||
async delete(rowKey: string) {
|
||||
return this.profileRepository.delete(this.partitionKey, rowKey);
|
||||
}
|
||||
}
|
||||
// async delete(rowKey: string) {
|
||||
// return this.profileRepository.delete(this.partitionKey, rowKey);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -16,7 +16,6 @@ import { CustomError } from '../error/customError';
|
||||
import { AuthGuard } from '@nestjs/passport'
|
||||
|
||||
@Controller('pilots')
|
||||
@UseGuards(AuthGuard('azure-ad'))
|
||||
export class PilotController {
|
||||
constructor(private readonly pilotService: PilotService) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user