Feature/59 add tracks to log form (#70)

* adding tracks

* adding tracks

* adding tracks
This commit was merged in pull request #70.
This commit is contained in:
2025-03-22 09:28:10 -05:00
committed by GitHub
parent 70fde43801
commit 08498a64d8
27 changed files with 819 additions and 303 deletions

View File

@@ -19,6 +19,7 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@azure/storage-blob": "^12.27.0",
"@microsoft/microsoft-graph-client": "^3.0.7",
"@nestjs/axios": "^3.0.3",
"@nestjs/common": "^10.0.0",
@@ -29,10 +30,12 @@
"@noahspan/azure-database": "^3.1.2",
"@noahspan/noahspan-modules": "^1.1.5",
"@schematics/angular": "^17.3.7",
"@types/multer": "^1.4.12",
"dotenv": "^16.4.7",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"uuid": "^10.0.0"
"uuid": "^10.0.0",
"uuidv4": "^6.2.13"
},
"devDependencies": {
"@microsoft/microsoft-graph-types": "^2.40.0",

View File

@@ -44,11 +44,6 @@ import configuration from './config/configuration';
provide: APP_FILTER,
useClass: HttpExceptionFilter
},
// {
// provide: APP_GUARD,
// useClass: AuthGuard
// },
// Reflector
]
})
export class AppModule {}

View File

@@ -0,0 +1,44 @@
import { BlobServiceClient, BlockBlobClient } from '@azure/storage-blob';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
@Injectable() export class FileService {
constructor(private readonly configService: ConfigService) {}
private containerName: string;
async getBlobServiceInstance() {
const connectionString = this.configService.get<string>('azureStorageConnectionString');
const blobServiceClient: BlobServiceClient = await BlobServiceClient.fromConnectionString(connectionString)
return blobServiceClient;
}
async getBlobClient(fileName: string): Promise<BlockBlobClient> {
const blobService = await this.getBlobServiceInstance();
const containerName = this.containerName;
const containerClient = blobService.getContainerClient(containerName);
const blockBlobClient = containerClient.getBlockBlobClient(fileName);
return blockBlobClient;
}
async uploadFile(file: Express.Multer.File, containerName: string, rowKey: string) {
this.containerName = containerName;
const blockBlobClient = await this.getBlobClient(`${rowKey}/${file.originalname}`);
const fileUrl = blockBlobClient.url;
await blockBlobClient.uploadData(file.buffer);
return fileUrl;
}
async deleteFile(containerName: string, rowKey:string, fileName: string) {
this.containerName = containerName;
const blockBlobClient = await this.getBlobClient(`${rowKey}/${fileName}`);
await blockBlobClient.deleteIfExists();
}
}

View File

@@ -6,6 +6,7 @@ export class LogInterceptor implements NestInterceptor {
const req = context.switchToHttp().getRequest();
const authHeader = req.headers.authorization;
const token = authHeader && authHeader.split(' ')[1];
console.log(token)
if (!token) {
return handler.handle().pipe(
@@ -22,6 +23,7 @@ export class LogInterceptor implements NestInterceptor {
routeFrom: log.routeFrom,
routeTo: log.routeTo,
durationOfFlight: log.durationOfFlight,
tracks: log.tracks,
notes: log.notes
};
});

View File

@@ -7,6 +7,8 @@ import {
Param,
Post,
Put,
Query,
UploadedFile,
UseGuards,
UseInterceptors
} from '@nestjs/common';
@@ -16,12 +18,16 @@ import { LogService } from './log.service';
import { CustomError } from '../error/customError';
import { AuthGuard } from '@noahspan/noahspan-modules';
import { LogInterceptor } from './interceptors/log.interceptor';
import { FileService } from '../file/file.service';
import { FileInterceptor } from '@nestjs/platform-express';
@Controller('logs')
@UseInterceptors(new LogInterceptor())
export class LogController {
constructor(private readonly logService: LogService) {}
constructor(
private readonly fileService: FileService,
private readonly logService: LogService
) {}
@Get(':partitionKey/:rowKey')
async find(
@@ -98,4 +104,35 @@ export class LogController {
throw new HttpException(customError.message, customError.statusCode);
}
}
@UseGuards(AuthGuard)
@Post(':partitionKey/:rowKey/track')
@UseInterceptors(FileInterceptor('file'))
async createTrack(@Param('rowKey') rowKey: string, @UploadedFile() file: Express.Multer.File) {
try {
const containerName = 'tracks';
const url = await this.fileService.uploadFile(file, containerName, rowKey);
return { url }
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
@UseGuards(AuthGuard)
@Delete(':partitionKey/:rowKey/track')
async deleteTrack(@Param('rowKey') rowKey: string, @Query('fileName') fileName: string): Promise<void> {
try {
console.log(fileName)
const containerName = 'tracks';
return await this.fileService.deleteFile(containerName, rowKey, fileName)
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
}

View File

@@ -22,5 +22,6 @@ export class LogDto {
night: number;
solo: number;
pilotInCommand: number;
tracks: string[];
notes: string;
}

View File

@@ -24,5 +24,6 @@ export class Log {
instrumentApproaches?: number | null;
instrumentHolds?: number | null;
instrumentNavTrack?: number | null;
tracks?: string[];
notes?: string;
}

View File

@@ -4,6 +4,7 @@ import { LogService } from './log.service';
import { AzureTableStorageModule } from '@noahspan/azure-database';
import { Log } from './log.entity';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { FileService } from '../file/file.service';
@Module({
imports: [
@@ -22,6 +23,10 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
}),
],
controllers: [LogController],
providers: [LogService]
providers: [
ConfigService,
FileService,
LogService
]
})
export class LogModule {}