@@ -37,6 +37,7 @@ const { dtoValidator } = require('../utilities');
3737const { ApiConfig } = require ( '../../config/index.js' ) ;
3838const { DtoFactory } = require ( '../../domain/dtos/DtoFactory.js' ) ;
3939const { runService } = require ( '../services/run/RunService.js' ) ;
40+ const { getAllBeamModes } = require ( '../services/beam/getAllBeamModes.js' ) ;
4041const { updateExpressResponseFromNativeError } = require ( '../express/updateExpressResponseFromNativeError.js' ) ;
4142const { runToHttpView } = require ( './runsToHttpView.js' ) ;
4243
@@ -297,6 +298,31 @@ const listReasonTypes = async (_request, response, _next) => {
297298 }
298299} ;
299300
301+ /**
302+ * Retrieve a list of unique beam modes
303+ *
304+ * @param {Object } _request The *request* object represents the HTTP request and has properties for the request query
305+ * string, parameters, body, HTTP headers, and so on.
306+ * @param {Object } response The *response* object represents the HTTP response that an Express app sends when it gets
307+ * an
308+ * HTTP request.
309+ * @param {Function } _next The *next* object represents the next middleware function which is used to pass control to
310+ * the next middleware function.
311+ * @returns {undefined }
312+ */
313+ const listBeamModes = async ( _request , response , _next ) => {
314+ try {
315+ const beamModes = await getAllBeamModes ( ) ;
316+ if ( beamModes && beamModes . length > 0 ) {
317+ response . status ( 200 ) . json ( { data : beamModes } ) ;
318+ } else {
319+ response . status ( 204 ) . json ( { data : [ ] } ) ;
320+ }
321+ } catch {
322+ response . status ( 502 ) . json ( { errors : [ 'Unable to retrieve list of beam modes' ] } ) ;
323+ }
324+ } ;
325+
300326// eslint-disable-next-line jsdoc/require-param
301327/**
302328 * Retrieve distinct combination of levels of alice L3 and dipole current rounded to kilo amperes
@@ -323,6 +349,7 @@ module.exports = {
323349 getLogsByRunNumberHandler,
324350 getFlpsByRunNumberHandler,
325351 listReasonTypes,
352+ listBeamModes,
326353 listRuns,
327354 startRun,
328355 updateRunByRunNumber,
0 commit comments