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

@@ -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 {}