limiting log data returned for unauthenticated users (#64)
This commit was merged in pull request #64.
This commit is contained in:
@@ -27,7 +27,7 @@
|
|||||||
"@nestjs/passport": "^10.0.3",
|
"@nestjs/passport": "^10.0.3",
|
||||||
"@nestjs/platform-express": "^10.0.0",
|
"@nestjs/platform-express": "^10.0.0",
|
||||||
"@noahspan/azure-database": "^3.1.2",
|
"@noahspan/azure-database": "^3.1.2",
|
||||||
"@noahspan/noahspan-modules": "^1.0.0",
|
"@noahspan/noahspan-modules": "^1.1.5",
|
||||||
"@schematics/angular": "^17.3.7",
|
"@schematics/angular": "^17.3.7",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ import configuration from './config/configuration';
|
|||||||
provide: APP_FILTER,
|
provide: APP_FILTER,
|
||||||
useClass: HttpExceptionFilter
|
useClass: HttpExceptionFilter
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
provide: APP_GUARD,
|
// provide: APP_GUARD,
|
||||||
useClass: AuthGuard
|
// useClass: AuthGuard
|
||||||
},
|
// },
|
||||||
Reflector
|
// Reflector
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
39
api/src/log/interceptors/log.interceptor.ts
Normal file
39
api/src/log/interceptors/log.interceptor.ts
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,20 +7,22 @@ import {
|
|||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
UseGuards
|
UseGuards,
|
||||||
|
UseInterceptors
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { LogDto } from './log.dto';
|
import { LogDto } from './log.dto';
|
||||||
import { Log } from './log.entity';
|
import { Log } from './log.entity';
|
||||||
import { LogService } from './log.service';
|
import { LogService } from './log.service';
|
||||||
import { CustomError } from '../error/customError';
|
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')
|
@Controller('logs')
|
||||||
|
@UseInterceptors(new LogInterceptor())
|
||||||
export class LogController {
|
export class LogController {
|
||||||
constructor(private readonly logService: LogService) {}
|
constructor(private readonly logService: LogService) {}
|
||||||
|
|
||||||
@Public()
|
|
||||||
@Get(':partitionKey/:rowKey')
|
@Get(':partitionKey/:rowKey')
|
||||||
async find(
|
async find(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
@@ -35,7 +37,6 @@ export class LogController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public()
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll(): Promise<Log[]> {
|
async findAll(): Promise<Log[]> {
|
||||||
try {
|
try {
|
||||||
@@ -47,6 +48,7 @@ export class LogController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Body() logDto: LogDto): Promise<Log> {
|
async create(@Body() logDto: LogDto): Promise<Log> {
|
||||||
try {
|
try {
|
||||||
@@ -62,6 +64,7 @@ export class LogController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Put(':partitionKey/:rowKey')
|
@Put(':partitionKey/:rowKey')
|
||||||
async update(
|
async update(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
@@ -81,6 +84,7 @@ export class LogController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Delete(':partitionKey/:rowKey')
|
@Delete(':partitionKey/:rowKey')
|
||||||
async delete(
|
async delete(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class PilotInterceptor implements NestInterceptor {
|
|||||||
name: pilot.name
|
name: pilot.name
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
console.log(pilots)
|
|
||||||
return pilots;
|
return pilots;
|
||||||
} else {
|
} else {
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import {
|
|||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
|
UseGuards,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { PilotDto } from './pilot.dto';
|
import { PilotDto } from './pilot.dto';
|
||||||
import { Pilot } from './pilot.entity';
|
import { Pilot } from './pilot.entity';
|
||||||
import { PilotService } from './pilot.service';
|
import { PilotService } from './pilot.service';
|
||||||
import { CustomError } from '../error/customError';
|
import { CustomError } from '../error/customError';
|
||||||
import { Public } from '@noahspan/noahspan-modules'
|
import { AuthGuard } from '@noahspan/noahspan-modules'
|
||||||
import { PilotInterceptor } from './interceptors/pilot.interceptor';
|
import { PilotInterceptor } from './interceptors/pilot.interceptor';
|
||||||
|
|
||||||
@Controller('pilots')
|
@Controller('pilots')
|
||||||
@@ -21,7 +22,6 @@ import { PilotInterceptor } from './interceptors/pilot.interceptor';
|
|||||||
export class PilotController {
|
export class PilotController {
|
||||||
constructor(private readonly pilotService: PilotService) {}
|
constructor(private readonly pilotService: PilotService) {}
|
||||||
|
|
||||||
@Public()
|
|
||||||
@Get(':partitionKey/:rowKey')
|
@Get(':partitionKey/:rowKey')
|
||||||
async find(
|
async find(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
@@ -36,7 +36,6 @@ export class PilotController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public()
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll() {
|
async findAll() {
|
||||||
try {
|
try {
|
||||||
@@ -48,6 +47,7 @@ export class PilotController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Body() pilotDto: PilotDto) {
|
async create(@Body() pilotDto: PilotDto) {
|
||||||
try {
|
try {
|
||||||
@@ -78,6 +78,7 @@ export class PilotController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Put(':partitionKey/:rowKey')
|
@Put(':partitionKey/:rowKey')
|
||||||
async update(
|
async update(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
@@ -112,6 +113,7 @@ export class PilotController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
@Delete(':partitionKey/:rowKey')
|
@Delete(':partitionKey/:rowKey')
|
||||||
async delete(
|
async delete(
|
||||||
@Param('partitionKey') partitionKey: string,
|
@Param('partitionKey') partitionKey: string,
|
||||||
|
|||||||
@@ -129,10 +129,56 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const columns: ColumnDef<ILogbookEntry>[] = [
|
const unauthColumns: ColumnDef<ILogbookEntry>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: 'pilotName',
|
accessorKey: 'pilotName',
|
||||||
header: 'Pilot'
|
header: 'Pilot',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'date',
|
||||||
|
header: 'Date'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'aircraftMakeModel',
|
||||||
|
header: 'Aircraft Make & Model'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'route',
|
||||||
|
header: 'Route of Flight',
|
||||||
|
meta: {
|
||||||
|
headerAlign: 'center'
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
accessorKey: 'routeFrom',
|
||||||
|
header: 'From'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'routeTo',
|
||||||
|
header: 'To'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'durationOfFlight',
|
||||||
|
header: 'Duration Of Flight',
|
||||||
|
meta: {
|
||||||
|
align: 'right',
|
||||||
|
headerAlign: 'right'
|
||||||
|
},
|
||||||
|
cell: (info: any) =>
|
||||||
|
info.getValue() ? parseFloat(info.getValue()).toFixed(1) : ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'notes',
|
||||||
|
header: 'Notes'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const authColumns: ColumnDef<ILogbookEntry>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'pilotName',
|
||||||
|
header: 'Pilot',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'date',
|
accessorKey: 'date',
|
||||||
@@ -144,7 +190,7 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'aircraftIdentity',
|
accessorKey: 'aircraftIdentity',
|
||||||
header: 'Aircraft Identity'
|
header: 'Aircraft Identity',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'route',
|
id: 'route',
|
||||||
@@ -390,7 +436,7 @@ const Logbook: React.FC<unknown> = () => {
|
|||||||
{!state.isLoading && (
|
{!state.isLoading && (
|
||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
{state.entries.length > 0 && (
|
{state.entries.length > 0 && (
|
||||||
<Table columns={columns} data={state.entries} />
|
<Table columns={isAuthenticated ? authColumns : unauthColumns} data={state.entries} />
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ version: '3.8'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
azurite:
|
azurite:
|
||||||
container_name: azurite
|
container_name: azurite-flying
|
||||||
image: mcr.microsoft.com/azure-storage/azurite
|
image: mcr.microsoft.com/azure-storage/azurite
|
||||||
ports:
|
ports:
|
||||||
- '10000:10000'
|
- '10000:10000'
|
||||||
|
|||||||
593
pnpm-lock.yaml
generated
593
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user