Refactoring
This commit is contained in:
@@ -3,69 +3,20 @@ import {
|
||||
Get,
|
||||
Headers,
|
||||
Query,
|
||||
Res,
|
||||
StreamableFile
|
||||
} from '@nestjs/common';
|
||||
import { Client as MsGraphClient } from '@microsoft/microsoft-graph-client';
|
||||
import { MsGraphService, Public } from '@noahspan/noahspan-modules';
|
||||
import { FeatureFlagValue } from '@azure/app-configuration';
|
||||
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';
|
||||
import { DaprService } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(
|
||||
private readonly appService: AppService,
|
||||
private readonly daprService: DaprService,
|
||||
private readonly msGraphService: MsGraphService
|
||||
) {}
|
||||
|
||||
// @Public()
|
||||
// @Get('featureFlags')
|
||||
// async getFeatureFlags(
|
||||
// @Query() query: any
|
||||
// ): Promise<{ key: string; enabled: boolean }[]> {
|
||||
// try {
|
||||
// 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(
|
||||
// featureFlagKeys,
|
||||
// featureFlagLabel
|
||||
// );
|
||||
|
||||
// return featureFlags;
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
|
||||
@Public()
|
||||
@Get('featureFlags')
|
||||
async getFeatureFlags(@Query() query: any): Promise<void> {
|
||||
try {
|
||||
// const config = await this.daprService.daprClient.configuration.get('app-config', ['flying-logbook'], {
|
||||
// 'label': 'dev'
|
||||
// })
|
||||
console.log('====== BLAH ======');
|
||||
const config =
|
||||
await this.daprService.daprClient.configuration.get('app-config');
|
||||
|
||||
console.log('====== Config ======: ' + config);
|
||||
} catch (error) {
|
||||
console.log(`======= ERROR ======: ${error}`);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
@Get('userPhoto')
|
||||
async getProfilePhoto(@Headers() headers: any): Promise<StreamableFile> {
|
||||
try {
|
||||
|
||||
@@ -4,81 +4,42 @@ import { AppService } from './app.service';
|
||||
import { AuthGuard, AuthModule } from '@noahspan/noahspan-modules';
|
||||
import { MsGraphModule } from '@noahspan/noahspan-modules';
|
||||
import { APP_GUARD } from '@nestjs/core';
|
||||
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 { HttpExceptionFilter } from './filters/http-exception.filter';
|
||||
import { DaprModule, DaprService } from '@noahspan/noahspan-modules';
|
||||
import { AzureTableStorageModule } from '@noahspan/azure-database';
|
||||
|
||||
const secretStoreName = 'key-vault';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import configuration from './config/configuration';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
AuthModule.registerAsync({
|
||||
imports: [DaprModule],
|
||||
useFactory: async (daprService: DaprService) => {
|
||||
const clientIdSecret = await daprService.daprClient.secret.get(
|
||||
secretStoreName,
|
||||
'client-id'
|
||||
);
|
||||
const clientSecret = await daprService.daprClient.secret.get(
|
||||
secretStoreName,
|
||||
'client-secret'
|
||||
);
|
||||
const tenantIdSecret = await daprService.daprClient.secret.get(
|
||||
secretStoreName,
|
||||
'tenant-id'
|
||||
);
|
||||
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
clientId: clientIdSecret['client-id'].toString(),
|
||||
clientSecret: clientSecret['client-secret'].toString(),
|
||||
tenantId: tenantIdSecret['tenant-id'].toString()
|
||||
clientId: configService.get<string>('clientId'),
|
||||
clientSecret: configService.get<string>('clientSecret'),
|
||||
tenantId: configService.get<string>('tenantId')
|
||||
};
|
||||
},
|
||||
inject: [DaprService]
|
||||
inject: [ConfigService]
|
||||
}),
|
||||
AzureTableStorageModule.forRootAsync({
|
||||
imports: [DaprModule],
|
||||
useFactory: async (daprService: DaprService) => {
|
||||
const connectionString = await daprService.daprClient.secret.get(
|
||||
secretStoreName,
|
||||
'azure-storage-connection-string'
|
||||
);
|
||||
|
||||
return {
|
||||
connectionString:
|
||||
connectionString['azure-storage-connection-string'].toString()
|
||||
};
|
||||
},
|
||||
inject: [DaprService]
|
||||
ConfigModule.forRoot({
|
||||
load: [configuration]
|
||||
}),
|
||||
DaprModule,
|
||||
FeatureFlagModule,
|
||||
LogModule,
|
||||
MsGraphModule.registerAsync({
|
||||
imports: [DaprModule],
|
||||
useFactory: async (daprService: DaprService) => {
|
||||
const clientIdSecret = await daprService.daprClient.secret.get(
|
||||
secretStoreName,
|
||||
'client-id'
|
||||
);
|
||||
const clientSecret = await daprService.daprClient.secret.get(
|
||||
secretStoreName,
|
||||
'client-secret'
|
||||
);
|
||||
const tenantIdSecret = await daprService.daprClient.secret.get(
|
||||
secretStoreName,
|
||||
'tenant-id'
|
||||
);
|
||||
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
clientId: clientIdSecret['client-id'].toString(),
|
||||
clientSecret: clientSecret['client-secret'].toString(),
|
||||
tenantId: tenantIdSecret['tenant-id'].toString()
|
||||
clientId: configService.get<string>('clientId'),
|
||||
clientSecret: configService.get<string>('clientSecret'),
|
||||
tenantId: configService.get<string>('tenantId')
|
||||
};
|
||||
},
|
||||
inject: [DaprService]
|
||||
inject: [ConfigService]
|
||||
}),
|
||||
PilotModule
|
||||
],
|
||||
|
||||
6
api/src/config/configuration.ts
Normal file
6
api/src/config/configuration.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export default () => ({
|
||||
azureStorageConnectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
|
||||
clientId: process.env.CLIENT_ID,
|
||||
clientSecret: process.env.CLIENT_SECRET,
|
||||
tenantId: process.env.TENANT_ID
|
||||
})
|
||||
40
api/src/featureFlag/feature-flag.controller.ts
Normal file
40
api/src/featureFlag/feature-flag.controller.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
Param,
|
||||
} from '@nestjs/common';
|
||||
import { FeatureFlagService } from './feature-flag.service';
|
||||
import { CustomError, Public } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Controller('featureFlags')
|
||||
export class FeatureFlagController {
|
||||
constructor(private readonly featureFlagService: FeatureFlagService) {}
|
||||
|
||||
@Get(':partitionKey/:rowKey')
|
||||
@Public()
|
||||
async find(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@Param('rowKey') rowKey: string
|
||||
) {
|
||||
try {
|
||||
return await this.featureFlagService.find(partitionKey, rowKey);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Get()
|
||||
@Public()
|
||||
async findAll() {
|
||||
try {
|
||||
return await this.featureFlagService.findAll();
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
throw new HttpException(customError.message, customError.statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
5
api/src/featureFlag/feature-flag.dto.ts
Normal file
5
api/src/featureFlag/feature-flag.dto.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export class FeatureFlagDto {
|
||||
partitionKey: string;
|
||||
rowKey: string;
|
||||
active: string;
|
||||
}
|
||||
7
api/src/featureFlag/feature-flag.entity.ts
Normal file
7
api/src/featureFlag/feature-flag.entity.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { EntityString } from '@noahspan/azure-database';
|
||||
|
||||
export class FeatureFlag {
|
||||
@EntityString() partitionKey: string;
|
||||
@EntityString() rowKey: string;
|
||||
@EntityString() active: string;
|
||||
}
|
||||
27
api/src/featureFlag/feature-flag.module.ts
Normal file
27
api/src/featureFlag/feature-flag.module.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { FeatureFlagController } from './feature-flag.controller';
|
||||
import { FeatureFlagService } from './feature-flag.service';
|
||||
import { AzureTableStorageModule } from '@noahspan/azure-database';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { FeatureFlag } from './feature-flag.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
AzureTableStorageModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
connectionString: configService.get<string>('azureStorageConnectionString')
|
||||
};
|
||||
},
|
||||
inject: [ConfigService]
|
||||
}),
|
||||
AzureTableStorageModule.forFeature(FeatureFlag, {
|
||||
createTableIfNotExists: false,
|
||||
table: 'featureFlags'
|
||||
}),
|
||||
],
|
||||
controllers: [FeatureFlagController],
|
||||
providers: [FeatureFlagService]
|
||||
})
|
||||
export class FeatureFlagModule {}
|
||||
18
api/src/featureFlag/feature-flag.service.ts
Normal file
18
api/src/featureFlag/feature-flag.service.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository, Repository } from '@noahspan/azure-database';
|
||||
import { FeatureFlag } from './feature-flag.entity';
|
||||
|
||||
@Injectable()
|
||||
export class FeatureFlagService {
|
||||
constructor(
|
||||
@InjectRepository(FeatureFlag) private readonly featureFlagRepository: Repository<FeatureFlag>
|
||||
) {}
|
||||
|
||||
async find(partitionKey: string, rowKey: string): Promise<FeatureFlag> {
|
||||
return await this.featureFlagRepository.find(partitionKey, rowKey);
|
||||
}
|
||||
|
||||
async findAll(): Promise<FeatureFlag[]> {
|
||||
return await this.featureFlagRepository.findAll();
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
||||
const response = ctx.getResponse<Response>();
|
||||
const request = ctx.getRequest<Request>();
|
||||
const status = excpetion.getStatus();
|
||||
console.log(excpetion.cause);
|
||||
|
||||
response.status(status).json({
|
||||
name: excpetion.cause,
|
||||
|
||||
@@ -48,7 +48,7 @@ export class LogController {
|
||||
const log = new Log();
|
||||
|
||||
Object.assign(log, logDto);
|
||||
console.log(log);
|
||||
|
||||
return await this.logService.create(log);
|
||||
} catch (error) {
|
||||
const customError = error as CustomError;
|
||||
|
||||
@@ -1,32 +1,25 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DaprModule, DaprService } from '@noahspan/noahspan-modules';
|
||||
import { LogController } from './log.controller';
|
||||
import { LogService } from './log.service';
|
||||
import { AzureTableStorageModule } from '@noahspan/azure-database';
|
||||
import { Log } from './log.entity';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
AzureTableStorageModule.forRootAsync({
|
||||
imports: [DaprModule],
|
||||
useFactory: async (daprService: DaprService) => {
|
||||
const connectionString = await daprService.daprClient.secret.get(
|
||||
'key-vault',
|
||||
'azure-storage-connection-string'
|
||||
);
|
||||
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
connectionString:
|
||||
connectionString['azure-storage-connection-string'].toString()
|
||||
connectionString: configService.get<string>('azureStorageConnectionString')
|
||||
};
|
||||
},
|
||||
inject: [DaprService]
|
||||
inject: [ConfigService]
|
||||
}),
|
||||
AzureTableStorageModule.forFeature(Log, {
|
||||
createTableIfNotExists: false,
|
||||
table: 'logs'
|
||||
}),
|
||||
DaprModule
|
||||
],
|
||||
controllers: [LogController],
|
||||
providers: [LogService]
|
||||
|
||||
@@ -5,8 +5,6 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
@Injectable()
|
||||
export class LogService {
|
||||
private readonly tableName = 'Logbook';
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Log) private readonly logRepository: Repository<Log>
|
||||
) {}
|
||||
|
||||
@@ -1,32 +1,25 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DaprModule, DaprService } from '@noahspan/noahspan-modules';
|
||||
import { PilotController } from './pilot.controller';
|
||||
import { PilotService } from './pilot.service';
|
||||
import { AzureTableStorageModule } from '@noahspan/azure-database';
|
||||
import { Pilot } from './pilot.entity';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
AzureTableStorageModule.forRootAsync({
|
||||
imports: [DaprModule],
|
||||
useFactory: async (daprService: DaprService) => {
|
||||
const connectionString = await daprService.daprClient.secret.get(
|
||||
'key-vault',
|
||||
'azure-storage-connection-string'
|
||||
);
|
||||
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
connectionString:
|
||||
connectionString['azure-storage-connection-string'].toString()
|
||||
connectionString: configService.get<string>('azureStorageConnectionString')
|
||||
};
|
||||
},
|
||||
inject: [DaprService]
|
||||
inject: [ConfigService]
|
||||
}),
|
||||
AzureTableStorageModule.forFeature(Pilot, {
|
||||
createTableIfNotExists: false,
|
||||
table: 'pilots'
|
||||
}),
|
||||
DaprModule
|
||||
],
|
||||
controllers: [PilotController],
|
||||
providers: [PilotService]
|
||||
|
||||
Reference in New Issue
Block a user