limiting log data returned for unauthenticated users (#64)

This commit was merged in pull request #64.
This commit is contained in:
2025-03-16 19:47:43 -05:00
committed by GitHub
parent cd08444c5f
commit 98cfe69afb
9 changed files with 580 additions and 142 deletions

View File

@@ -27,7 +27,7 @@
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@noahspan/azure-database": "^3.1.2",
"@noahspan/noahspan-modules": "^1.0.0",
"@noahspan/noahspan-modules": "^1.1.5",
"@schematics/angular": "^17.3.7",
"dotenv": "^16.4.7",
"reflect-metadata": "^0.2.2",

View File

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

View File

@@ -0,0 +1,39 @@
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
import { Observable, map } from 'rxjs';
export class LogInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, handler: CallHandler): Observable<any> {
const req = context.switchToHttp().getRequest();
const authHeader = req.headers.authorization;
const token = authHeader && authHeader.split(' ')[1];
if (!token) {
return handler.handle().pipe(
map((data) => {
if (data.length) {
const logs = data.map((log) => {
return {
partitionKey: log.partitionKey,
rowKey: log.rowKey,
pilotId: log.pilotId,
pilotName: log.pilotName,
date: log.date,
aircraftMakeModel: log.aircraftMakeModel,
routeFrom: log.routeFrom,
routeTo: log.routeTo,
durationOfFlight: log.durationOfFlight,
notes: log.notes
};
});
return logs;
} else {
return data;
}
})
);
}
return handler.handle().pipe(map((data) => data));
}
}

View File

@@ -7,20 +7,22 @@ import {
Param,
Post,
Put,
UseGuards
UseGuards,
UseInterceptors
} from '@nestjs/common';
import { LogDto } from './log.dto';
import { Log } from './log.entity';
import { LogService } from './log.service';
import { CustomError } from '../error/customError';
import { Public } from '@noahspan/noahspan-modules';
import { AuthGuard } from '@noahspan/noahspan-modules';
import { LogInterceptor } from './interceptors/log.interceptor';
@Controller('logs')
@UseInterceptors(new LogInterceptor())
export class LogController {
constructor(private readonly logService: LogService) {}
@Public()
@Get(':partitionKey/:rowKey')
async find(
@Param('partitionKey') partitionKey: string,
@@ -35,7 +37,6 @@ export class LogController {
}
}
@Public()
@Get()
async findAll(): Promise<Log[]> {
try {
@@ -47,6 +48,7 @@ export class LogController {
}
}
@UseGuards(AuthGuard)
@Post()
async create(@Body() logDto: LogDto): Promise<Log> {
try {
@@ -62,6 +64,7 @@ export class LogController {
}
}
@UseGuards(AuthGuard)
@Put(':partitionKey/:rowKey')
async update(
@Param('partitionKey') partitionKey: string,
@@ -81,6 +84,7 @@ export class LogController {
}
}
@UseGuards(AuthGuard)
@Delete(':partitionKey/:rowKey')
async delete(
@Param('partitionKey') partitionKey: string,

View File

@@ -19,7 +19,7 @@ export class PilotInterceptor implements NestInterceptor {
name: pilot.name
};
});
console.log(pilots)
return pilots;
} else {
return data;

View File

@@ -7,13 +7,14 @@ import {
Param,
Post,
Put,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { PilotDto } from './pilot.dto';
import { Pilot } from './pilot.entity';
import { PilotService } from './pilot.service';
import { CustomError } from '../error/customError';
import { Public } from '@noahspan/noahspan-modules'
import { AuthGuard } from '@noahspan/noahspan-modules'
import { PilotInterceptor } from './interceptors/pilot.interceptor';
@Controller('pilots')
@@ -21,7 +22,6 @@ import { PilotInterceptor } from './interceptors/pilot.interceptor';
export class PilotController {
constructor(private readonly pilotService: PilotService) {}
@Public()
@Get(':partitionKey/:rowKey')
async find(
@Param('partitionKey') partitionKey: string,
@@ -36,7 +36,6 @@ export class PilotController {
}
}
@Public()
@Get()
async findAll() {
try {
@@ -48,6 +47,7 @@ export class PilotController {
}
}
@UseGuards(AuthGuard)
@Post()
async create(@Body() pilotDto: PilotDto) {
try {
@@ -78,6 +78,7 @@ export class PilotController {
}
}
@UseGuards(AuthGuard)
@Put(':partitionKey/:rowKey')
async update(
@Param('partitionKey') partitionKey: string,
@@ -112,6 +113,7 @@ export class PilotController {
}
}
@UseGuards(AuthGuard)
@Delete(':partitionKey/:rowKey')
async delete(
@Param('partitionKey') partitionKey: string,