define the properties as specific as possible

This commit is contained in:
Sven Czarnian
2022-10-22 21:41:38 +02:00
parent 822709f577
commit 5eb83ef649
6 changed files with 90 additions and 36 deletions

View File

@@ -1,24 +1,42 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import { PerformanceEntry } from './performanceentry.model';
import {
PerformanceEntry,
PerformanceEntrySchema,
} from './performanceentry.model';
export type PerformanceDocument = Performance & Document;
@Schema()
export class Performance {
@Prop({ required: true })
@Prop({
type: String,
required: true,
})
icaoCode: string;
@Prop({ required: true, type: PerformanceEntry })
@Prop({
required: true,
type: PerformanceEntrySchema,
})
aboveFL240: PerformanceEntry;
@Prop({ required: true, type: PerformanceEntry })
@Prop({
required: true,
type: PerformanceEntrySchema,
})
aboveFL100: PerformanceEntry;
@Prop({ required: true, type: PerformanceEntry })
@Prop({
required: true,
type: PerformanceEntrySchema,
})
belowFL100: PerformanceEntry;
@Prop({ required: true })
@Prop({
required: true,
type: Number,
})
minimalApproachSpeed: number;
}

View File

@@ -5,10 +5,16 @@ export type PerformanceEntryDocument = PerformanceEntry & Document;
@Schema()
export class PerformanceEntry {
@Prop({ required: true })
@Prop({
required: true,
type: Number,
})
speed: number;
@Prop({ required: true })
@Prop({
required: true,
type: Number,
})
rateOfDescend: number;
}

View File

@@ -21,26 +21,41 @@ export class PerformanceService {
private async updatePerformanceData(
performanceData: Record<string, any>,
version: SemanticVersionDto,
): Promise<boolean> {
): Promise<string[]> {
return this.performanceModel.deleteMany({}).then(async () => {
const invalidEntries: string[] = [];
for (const key in performanceData) {
if (key !== 'FILEINFO') {
await this.performanceModel.create({
icaoCode: key,
aboveFL240: {
speed: performanceData[key]['speedabovefl240'],
rateOfDescend: performanceData[key]['rodabovefl240'],
},
aboveFL100: {
speed: performanceData[key]['speedabovefl100'],
rateOfDescend: performanceData[key]['rodabovefl100'],
},
belowFL100: {
speed: performanceData[key]['speedbelowfl100'],
rateOfDescend: performanceData[key]['rodbelowfl100'],
},
minimalApproachSpeed: performanceData[key]['speedapproach'],
});
const validAircraft =
performanceData[key]['speedabovefl240'] !== undefined &&
performanceData[key]['rodabovefl240'] !== undefined &&
performanceData[key]['speedabovefl100'] !== undefined &&
performanceData[key]['rodabovefl100'] !== undefined &&
performanceData[key]['speedbelowfl100'] !== undefined &&
performanceData[key]['rodbelowfl100'] !== undefined &&
performanceData[key]['speedapproach'] !== undefined;
if (!validAircraft) {
invalidEntries.push(key);
} else {
await this.performanceModel.create({
icaoCode: key,
aboveFL240: {
speed: performanceData[key]['speedabovefl240'],
rateOfDescend: performanceData[key]['rodabovefl240'],
},
aboveFL100: {
speed: performanceData[key]['speedabovefl100'],
rateOfDescend: performanceData[key]['rodabovefl100'],
},
belowFL100: {
speed: performanceData[key]['speedbelowfl100'],
rateOfDescend: performanceData[key]['rodbelowfl100'],
},
minimalApproachSpeed: performanceData[key]['speedapproach'],
});
}
}
}
@@ -50,15 +65,15 @@ export class PerformanceService {
version,
);
return true;
return invalidEntries;
});
}
private async validateAndUpdatePerformanceData(): Promise<boolean> {
private async validateAndUpdatePerformanceData(): Promise<string[]> {
// read the performance file and validate the version length
const data = PerformanceService.readPerformanceFile();
const versionParts = (data['FILEINFO']['version'] as string).split('.');
if (versionParts.length !== 3) return false;
if (versionParts.length !== 3) return [];
// create the fileversion
const fileversion: SemanticVersionDto = {
@@ -84,7 +99,7 @@ export class PerformanceService {
return this.updatePerformanceData(data, fileversion);
}
return false;
return [];
})
.catch(() => this.updatePerformanceData(data, fileversion));
}

View File

@@ -5,19 +5,34 @@ export type VersioningDocument = Versioning & Document;
@Schema()
export class Versioning {
@Prop({ required: true })
@Prop({
required: true,
type: String,
})
componentName: string;
@Prop({ required: true })
@Prop({
required: true,
type: String,
})
createdAt: string;
@Prop({ required: true })
@Prop({
required: true,
type: Number,
})
versionMain: number;
@Prop({ required: true })
@Prop({
required: true,
type: Number,
})
versionMajor: number;
@Prop({ required: true })
@Prop({
required: true,
type: Number,
})
versionMinor: number;
}

View File

@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { VersioningSchema } from './versioning.model';
import { VersioningSchema } from './models/versioning.model';
import { VersioningService } from './versioning.service';
@Module({

View File

@@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { SemanticVersionDto } from './dto/semanticversion.dto';
import { Versioning, VersioningDocument } from './versioning.model';
import { Versioning, VersioningDocument } from './models/versioning.model';
@Injectable()
export class VersioningService {