migrating to sqlite

This commit is contained in:
2025-10-24 08:31:13 -05:00
parent 05b17878d7
commit 280b222d9a
69 changed files with 6053 additions and 1885 deletions

View File

@@ -42,6 +42,7 @@
"dotenv": "^16.6.1",
"express-session": "^1.18.2",
"jwks-rsa": "^3.2.0",
"jwt-decode": "^4.0.0",
"node-gyp": "^11.4.1",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",

View File

@@ -31,12 +31,12 @@ import { join } from 'path';
load: [configuration]
}),
// HealthModule,
// LogModule,
LogModule,
PilotModule,
ServeStaticModule.forRoot({
rootPath: join(__dirname, '../..', 'client', 'dist')
}),
// TrackModule,
TrackModule,
TypeOrmModule.forRoot(dataSourceOptions),
MsGraphModule.registerAsync({
inject: [ConfigService],

View File

@@ -0,0 +1,5 @@
import { JwtPayload } from "jwt-decode";
export interface CustomJwtPayload extends JwtPayload {
roles: string[];
}

View File

@@ -1,42 +0,0 @@
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
import { Observable, map } from 'rxjs';
import { LogEntity } from '../log.entity';
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: LogEntity[]) => {
if (data.length) {
const logs = data.map((log: LogEntity) => {
return {
id: log.id,
pilot: {
name: log.pilot.name
},
date: log.date,
aircraftMakeModel: log.aircraftMakeModel,
routeFrom: log.routeFrom,
routeTo: log.routeTo,
durationOfFlight: log.durationOfFlight,
tracks: log.tracks,
notes: log.notes
};
});
return logs;
} else {
return data;
}
})
);
}
return handler.handle().pipe(map((data) => data));
}
}

View File

@@ -15,11 +15,13 @@ import { LogEntity } from './log.entity';
import { LogService } from './log.service';
import { CustomError } from '../error/customError';
import { AuthGuard } from '@noahspan/noahspan-modules';
import { LogInterceptor } from './interceptors/log.interceptor';
import { LogInterceptor } from './log.interceptor';
import { FileService } from '../file/file.service';
import { DeleteResult, InsertResult, UpdateResult } from 'typeorm';
@Controller('logs')
@UseInterceptors(new LogInterceptor())
// @UseGuards(AuthGuard)
export class LogController {
constructor(
private readonly fileService: FileService,
@@ -28,11 +30,11 @@ export class LogController {
@Get(':id')
@UseInterceptors(new LogInterceptor())
async find(
@Param('id') id: string,
): Promise<LogEntity> {
try {
console.log(id)
return await this.logService.find(id);
} catch (error) {
const customError = error as CustomError;
@@ -42,7 +44,6 @@ export class LogController {
}
@Get()
@UseInterceptors(new LogInterceptor())
async findAll(): Promise<LogEntity[]> {
try {
return await this.logService.findAll();
@@ -53,7 +54,7 @@ export class LogController {
}
}
// @UseGuards(AuthGuard)
@Post()
async create(@Body() logDto: LogDto): Promise<InsertResult> {
try {
@@ -65,22 +66,22 @@ export class LogController {
}
}
// @UseGuards(AuthGuard)
@Put(':id')
async update(
@Param('id') id: string,
@Body() logDto: LogDto
): Promise<UpdateResult> {
try {
console.log(id)
console.log(logDto)
return await this.logService.update(id, logDto);
} catch (error) {
const customError = error as CustomError;
console.log(error)
throw new HttpException(customError.message, customError.statusCode);
}
}
// @UseGuards(AuthGuard)
@Delete(':id')
async delete(
@Param('id') id: string,

View File

@@ -24,5 +24,5 @@ export class LogDto {
solo?: number;
pilotInCommand?: number;
notes?: string;
pilot?: PilotEntity;
tracks?: []
}

View File

@@ -7,6 +7,9 @@ export class LogEntity {
@PrimaryGeneratedColumn('uuid')
id: string
@Column()
pilotId: string;
@Column()
date: Date;

View File

@@ -0,0 +1,39 @@
import { CallHandler, ExecutionContext, NestInterceptor, UnauthorizedException } from '@nestjs/common';
import { Observable, map } from 'rxjs';
import { LogEntity } from './log.entity';
import { jwtDecode } from 'jwt-decode';
import { CustomJwtPayload } from 'src/interfaces/customJwtPayload.interface';
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];
const jwtPayload: CustomJwtPayload = jwtDecode(token);
return handler.handle().pipe(
map((data: LogEntity[]) => {
if (data.length > 0 && jwtPayload.roles.includes('Flying.Read')) {
const logs = data.map((log: LogEntity) => {
return {
id: log.id,
pilot: {
name: log.pilot.name
},
date: log.date,
aircraftMakeModel: log.aircraftMakeModel,
routeFrom: log.routeFrom,
routeTo: log.routeTo,
durationOfFlight: log.durationOfFlight,
tracks: log.tracks,
};
});
return logs;
} else {
return data;
}
})
);
}
}

View File

@@ -18,7 +18,7 @@ export class LogService {
async find(id: string): Promise<LogEntity> {
const logEntity: LogEntity = await this.logRepository.findOne({
where: { id: id },
relations: ['pilot', 'tracks']
// relations: ['pilot', 'tracks']
});
return logEntity;

View File

@@ -1,35 +0,0 @@
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
import { Observable, map } from 'rxjs';
export class PilotInterceptor 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 pilots = data.map((pilot) => {
return {
partitionKey: pilot.partitionKey,
rowKey: pilot.rowKey,
id: pilot.id,
name: pilot.name,
certificates: pilot.certificates,
endorsements: pilot.endorsements
};
});
return pilots;
} else {
return data;
}
})
);
}
return handler.handle().pipe(map((data) => data));
}
}

View File

@@ -14,11 +14,12 @@ import { PilotDto } from './pilot.dto';
import { PilotEntity } from './pilot.entity';
import { PilotService } from './pilot.service';
import { CustomError } from '../error/customError';
import { PilotInterceptor } from './interceptors/pilot.interceptor';
import { PilotInterceptor } from './pilot.interceptor';
import { AuthGuard } from '@noahspan/noahspan-modules';
@Controller('pilots')
// @UseInterceptors(new PilotInterceptor())
@UseInterceptors(new PilotInterceptor())
@UseGuards(AuthGuard)
export class PilotController {
constructor(private readonly pilotService: PilotService) {}
@@ -34,7 +35,6 @@ export class PilotController {
}
@Get()
@UseGuards(AuthGuard)
async findAll() {
try {
return await this.pilotService.findAll();
@@ -45,7 +45,6 @@ export class PilotController {
}
}
@UseGuards(AuthGuard)
@Post()
async create(@Body() pilotDto: PilotDto) {
try {
@@ -57,7 +56,6 @@ export class PilotController {
}
}
// @UseGuards(AuthGuard)
@Put(':id')
async update(
@Param('id') id: string,
@@ -72,7 +70,6 @@ export class PilotController {
}
}
// @UseGuards(AuthGuard)
@Delete(':id')
async delete(
@Param('id') id: string,

View File

@@ -0,0 +1,33 @@
import { CallHandler, ExecutionContext, NestInterceptor, UnauthorizedException } from '@nestjs/common';
import { jwtDecode } from 'jwt-decode';
import { Observable, map } from 'rxjs';
import { CustomJwtPayload } from 'src/interfaces/customJwtPayload.interface';
import { PilotEntity } from './pilot.entity';
export class PilotInterceptor 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];
const jwtPayload: CustomJwtPayload = jwtDecode(token);
return handler.handle().pipe(
map((data: PilotEntity[]) => {
if (data.length && jwtPayload.roles.includes('Flying.Read')) {
const pilots = data.map((pilot) => {
return {
id: pilot.id,
name: pilot.name
};
});
return pilots;
} else if (data.length && jwtPayload.roles.includes('Flying.Write')) {
return data;
} else {
return UnauthorizedException;
}
})
);
}
}

View File

@@ -39,9 +39,11 @@ export class TrackController {
// }
// }
@UseGuards(AuthGuard)
@Get(':logId')
async findAll(@Param('logId') logId: string): Promise<TrackEntity[]> {
try {
console.log('logId: ' + logId)
return await this.trackService.findAll(logId);
} catch (error) {
const customError = error as CustomError;

View File

@@ -55,6 +55,7 @@ export class TrackService {
if (logEntity) {
const url = await this.fileService.uploadFile(file, this.containerName, logId);
console.log(url)
const track = this.trackRepository.create({
log: logEntity,
order: order,