Переглянути джерело

add a function to find the best performance table

Sven Czarnian 2 роки тому
батько
коміт
10818401e1
1 змінених файлів з 22 додано та 1 видалено
  1. 22 1
      src/performance/performance.service.ts

+ 22 - 1
src/performance/performance.service.ts

@@ -7,7 +7,7 @@ import { join } from 'path';
 import { SemanticVersionDto } from '../versioning/dto/semanticversion.dto';
 import { VersioningService } from '../versioning/versioning.service';
 import { LoggingService } from '../logging/logging.service';
-import { PerformanceDocument } from './models/performance.model';
+import { PerformanceDocument, Performance } from './models/performance.model';
 
 const COMPONENT_NAME = 'performance';
 
@@ -168,4 +168,25 @@ export class PerformanceService {
       }
     });
   }
+
+  async findAircraft(icao: string, wtc: string): Promise<Performance> {
+    return this.performanceModel
+      .findOne({ icaoCode: icao })
+      .then(async (response) => {
+        if (!response) {
+          switch (wtc) {
+            case 'L':
+              return this.performanceModel.findOne({ icaoCode: 'C172' });
+            case 'H':
+              return this.performanceModel.findOne({ icaoCode: 'B744' });
+            case 'J':
+              return this.performanceModel.findOne({ icaoCode: 'A388' });
+            case 'M':
+            default:
+              return this.performanceModel.findOne({ icaoCode: 'A320' });
+          }
+        }
+        return response;
+      });
+  }
 }