diff --git a/backend/package-lock.json b/backend/package-lock.json index b3b1259..48508b8 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1,13 +1,13 @@ { "name": "vacdm-backend", - "version": "0.0.1", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vacdm-backend", - "version": "0.0.1", - "license": "ISC", + "version": "1.1.0", + "license": "GPL3", "dependencies": { "@dotfionn/logger": "^1.0.1", "axios": "^0.27.2", diff --git a/backend/src/controllers/flow.controller.ts b/backend/src/controllers/flow.controller.ts index 8868345..dadf73d 100644 --- a/backend/src/controllers/flow.controller.ts +++ b/backend/src/controllers/flow.controller.ts @@ -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'; @@ -9,7 +12,6 @@ export async function getAllMeasures( res: Response, next: NextFunction ) { - try { const measures = await ecfmpService.getAllMeasures(); @@ -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 = { @@ -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) { diff --git a/backend/src/services/ecfmp.service.ts b/backend/src/services/ecfmp.service.ts index eb02f3c..176621d 100644 --- a/backend/src/services/ecfmp.service.ts +++ b/backend/src/services/ecfmp.service.ts @@ -213,7 +213,12 @@ export async function doesMeasureExist(ident: string): Promise { 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;