Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dotFionn committed May 22, 2023
2 parents 77c35a0 + 53bce51 commit d04b3e5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
6 changes: 3 additions & 3 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 33 additions & 13 deletions backend/src/controllers/flow.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { RogerPlugin, RogerPluginMeasure } from '@shared/interfaces/rogerPlugin.interface';
import { NextFunction, Request, Response } from "express";
import ecfmpService from "../services/ecfmp.service";
import {
RogerPlugin,
RogerPluginMeasure,
} from '@shared/interfaces/rogerPlugin.interface';
import { NextFunction, Request, Response } from 'express';
import ecfmpService from '../services/ecfmp.service';
import { EcfmpMeasure } from '@shared/interfaces/ecfmp.interface';
import { APIError } from '@shared/errors';

Expand All @@ -9,7 +12,6 @@ export async function getAllMeasures(
res: Response,
next: NextFunction
) {

try {
const measures = await ecfmpService.getAllMeasures();

Expand All @@ -27,23 +29,29 @@ export async function getLegacyMeasures(
let aerodromes = req.query.aerodromes;

if (aerodromes == null) {
return next(new APIError("aerodromes is a required query parameter", null, 400));
return next(
new APIError('aerodromes is a required query parameter', null, 400)
);
}

if (Array.isArray(aerodromes)) {
return next(new APIError("aerodromes must be a comma-separated string of ICAO-codes", null, 400));
return next(
new APIError(
'aerodromes must be a comma-separated string of ICAO-codes',
null,
400
)
);
}

let relevantAerodromes = aerodromes.toString().split(",");
let relevantAerodromes = aerodromes.toString().split(',');

try {
const measures = await ecfmpService.getAllMeasures();

const legacyMeasures: RogerPlugin = {MDI: []};


const legacyMeasures: RogerPlugin = { MDI: [] };

/* measures.forEach((element: EcfmpMeasure) => {
/* measures.forEach((element: EcfmpMeasure) => {
if (element.measure.type != "minimum_departure_interval") {return;}
let thisMeasure: RogerPluginMeasure = {
Expand All @@ -68,9 +76,21 @@ export async function getLegacyMeasures(
}
}

export async function editMeasure(req: Request, res: Response, next: NextFunction) {
export async function editMeasure(
req: Request,
res: Response,
next: NextFunction
) {
try {
const measure = await ecfmpService.editMeasure(req.body);
const { id } = req.params;

const numId = Number(id);

if (Number.isNaN(numId)) {
return res.status(400).json({ msg: 'id must be numeric' });
}

const measure = await ecfmpService.editMeasure(numId, req.body);

res.json(measure);
} catch (error) {
Expand Down
7 changes: 6 additions & 1 deletion backend/src/services/ecfmp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ export async function doesMeasureExist(ident: string): Promise<boolean> {

export async function editMeasure(measureId: number, measure: EcfmpMeasureDocument) {
try {
const updatedMeasure = await ecfmpModel.findOneAndUpdate({ id: measureId }, { enabled: measure.enabled }, {new: true}).exec();
const updatedMeasure = await ecfmpModel.findOneAndUpdate(
{ id: measureId },
{ enabled: measure.enabled },
{ new: true }
).exec();

return updatedMeasure;
} catch (e) {
throw e;
Expand Down

0 comments on commit d04b3e5

Please sign in to comment.