Skip to content

Commit 8797eb6

Browse files
committed
[O2B-1508] Refactor and relocate beam types API and service logic to be under LHCFills
Removed the dedicated beamsTypes controller, router, DTO, and use case. Moved the beam types endpoint under the lhcFills controller and router, and implemented the service logic in lib/server/services/beam/getAllBeamTypes.js. Updated frontend provider and imports to use the new endpoint and naming (beamTypes instead of beamsTypes).
1 parent 92c7f4f commit 8797eb6

15 files changed

Lines changed: 72 additions & 193 deletions

File tree

lib/database/repositories/LhcFillRepository.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const { models: { LhcFill }, sequelize } = require('../');
1515

1616
const Repository = require('./Repository');
1717
const { timestampToMysql } = require('../../server/utilities/timestampToMysql.js');
18-
const { QueryTypes, Op } = require('sequelize');
18+
const { QueryTypes } = require('sequelize');
1919

2020
/**
2121
* Return the SQL query to use to fetch the list of LHC fills numbers for fills with stable beams that ended in the given period
@@ -45,23 +45,6 @@ class LhcFillRepository extends Repository {
4545
super(LhcFill);
4646
}
4747

48-
/**
49-
* Return the list of LHC fills distict beam types.
50-
* @returns {Promise<object[]>}
51-
*/
52-
async getLhcFillDistinctBeamTypes() {
53-
return await LhcFill.findAll({
54-
attributes: [[sequelize.fn('DISTINCT', sequelize.col('beam_type')), 'beam_type']],
55-
where: {
56-
beamType: {
57-
[Op.not]: null,
58-
},
59-
},
60-
order: [['beam_type', 'ASC']],
61-
raw: true,
62-
});
63-
}
64-
6548
/**
6649
* Return the list of LHC fills numbers for fills with stable beams that ended in the given period
6750
*

lib/domain/dtos/GetAllBeamsTypesDto.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

lib/domain/dtos/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const CreateLhcFillDto = require('./CreateLhcFillDto');
1818
const CreateLogDto = require('./CreateLogDto');
1919
const CreateTagDto = require('./CreateTagDto');
2020
const EntityIdDto = require('./EntityIdDto');
21-
const GetAllBeamsTypesDto = require('./GetAllBeamsTypesDto.js');
2221
const GetAllEnvironmentsDto = require('./GetAllEnvironmentsDto');
2322
const GetAllLhcFillsDto = require('./GetAllLhcFillsDto');
2423
const GetAllLogAttachmentsDto = require('./GetAllLogAttachmentsDto');
@@ -57,7 +56,6 @@ module.exports = {
5756
CreateTagDto,
5857
EndRunDto,
5958
EntityIdDto,
60-
GetAllBeamsTypesDto,
6159
GetAllEnvironmentsDto,
6260
GetAllLhcFillsDto,
6361
GetAllLogAttachmentsDto,

lib/public/components/Filters/LhcFillsFilter/BeamsTypeFilterModel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14-
import { beamsTypesProvider } from '../../../services/beamsTypes/beamsTypesProvider.js';
14+
import { beamTypesProvider } from '../../../services/beamTypes/beamTypesProvider.js';
1515
import { SelectionModel } from '../../common/selection/SelectionModel.js';
1616

1717
/**
@@ -28,8 +28,8 @@ export class BeamsTypeFilterModel extends SelectionModel {
2828
multiple: true,
2929
allowEmpty: true });
3030

31-
beamsTypesProvider.items$.observe(() => {
32-
beamsTypesProvider.items$.getCurrent().apply({
31+
beamTypesProvider.items$.observe(() => {
32+
beamTypesProvider.items$.getCurrent().apply({
3333
Success: (types) => {
3434
beamTypes = types.map((type) => ({ value: String(type.beam_type) }));
3535
this.setAvailableOptions(beamTypes);

lib/public/services/beamsTypes/beamsTypesProvider.js renamed to lib/public/services/beamTypes/beamTypesProvider.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import { RemoteDataProvider } from '../RemoteDataProvider.js';
1717
/**
1818
* Service class to fetch beams types from the backend
1919
*/
20-
export class BeamsTypesProvider extends RemoteDataProvider {
20+
export class BeamTypesProvider extends RemoteDataProvider {
2121
/**
2222
* @inheritDoc
2323
*/
2424
async getRemoteData() {
25-
const { data } = await getRemoteData('/api/beamsTypes');
25+
const { data } = await getRemoteData('/api/lhcFills/beamTypes');
2626
return data;
2727
}
2828
}
2929

30-
export const beamsTypesProvider = new BeamsTypesProvider();
30+
export const beamTypesProvider = new BeamTypesProvider();

lib/server/controllers/beamsTypes.controller.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

lib/server/controllers/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313

1414
const AttachmentsController = require('./attachments.controller');
15-
const BeamsTypeController = require('./beamsTypes.controller.js');
1615
const ConfigurationController = require('./configuration.controller.js');
1716
const DetectorsController = require('./detectors.controller');
1817
const EnvironmentsController = require('./environments.controller');
@@ -27,7 +26,6 @@ const CtpTriggerCountersController = require('./ctpTriggerCounters.controller');
2726

2827
module.exports = {
2928
AttachmentsController,
30-
BeamsTypeController,
3129
ConfigurationController,
3230
DetectorsController,
3331
EnvironmentsController,

lib/server/controllers/lhcFill.controller.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const { ApiConfig } = require('../../config/index.js');
3535
const { DtoFactory } = require('../../domain/dtos/DtoFactory.js');
3636
const Joi = require('joi');
3737
const { logService } = require('../services/log/LogService.js');
38+
const { getAllBeamTypes } = require('../services/beam/getAllBeamTypes.js');
3839
const { updateExpressResponseFromNativeError } = require('../express/updateExpressResponseFromNativeError.js');
3940
const { lhcFillService } = require('../services/lhcFill/LhcFillService.js');
4041
const { runToHttpView } = require('./runsToHttpView.js');
@@ -256,6 +257,30 @@ const getAllLhcFillsWithStableBeamsEndedInPeriodHandler = async (request, respon
256257
}
257258
};
258259

260+
/**
261+
* Retrieve a list of unique beam types
262+
*
263+
* @param {Object} _request The *request* object represents the HTTP request and has properties for the request query
264+
* string, parameters, body, HTTP headers, and so on.
265+
* @param {Object} response The *response* object represents the HTTP response that an Express app sends when it gets
266+
* an HTTP request.
267+
* @param {NextFunction} _next The *next* object represents the next middleware function which is used to pass control to
268+
* the next middleware function.
269+
* @returns {undefined}
270+
*/
271+
const listBeamsTypes = async (_request, response, _next) => {
272+
try {
273+
const beamsTypes = await getAllBeamTypes();
274+
if (beamsTypes && beamsTypes.length > 0) {
275+
response.status(200).json({ data: beamsTypes });
276+
} else {
277+
response.status(204).json({ data: [] });
278+
}
279+
} catch {
280+
response.status(502).json({ errors: ['Unable to retrieve list of beam types'] });
281+
}
282+
};
283+
259284
module.exports = {
260285
createLhcFill,
261286
listLhcFills,
@@ -265,4 +290,5 @@ module.exports = {
265290
getLhcFillById,
266291
getAllLhcFillLogsHandler,
267292
getAllLhcFillsWithStableBeamsEndedInPeriodHandler,
293+
listBeamsTypes,
268294
};

lib/server/routers/beamsTypes.router.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/server/routers/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const { deepmerge, isPromise } = require('../../utilities');
1515

1616
const attachmentRoute = require('./attachments.router');
1717
const { configurationRouter } = require('./configuration.router.js');
18-
const { beamsTypesRouter } = require('./beamsTypes.router.js');
1918
const detectorsRoute = require('./detectors.router');
2019
const { dplProcessRouter } = require('./dplProcess.router.js');
2120
const environmentRoute = require('./environments.router');
@@ -41,7 +40,6 @@ const { ctpTriggerCountersRouter } = require('./ctpTriggerCounters.router.js');
4140

4241
const routes = [
4342
attachmentRoute,
44-
beamsTypesRouter,
4543
configurationRouter,
4644
detectorsRoute,
4745
dataPassesRouter,

0 commit comments

Comments
 (0)